【freo】【freoTips】【freo変数一覧】親ページ表示プラグインで親ページのオプションを表示する方法
- 2014/06/10 22:07
- 親ページ表示プラグイン
- 109
freoのページ画面では、親ページの情報を取得することができます。
freoには親ページ表示プラグインがデフォルトで備わっているので、あるページの親ページの情報を取得することができます。
【関連リンク】
32877|親ページの情報を取得する方法
下記に、親ページのオプションの情報を取得する方法を紹介します。
親ページのオプション情報を表示する方法
親ページの情報についての解説
あるページにとって、親ページは1ページしかありません。
よって、下記の変数をテンプレートに記載するだけで、親ページについての様々な情報を表示することができます。
親ページのオプションのとりかたについての解説
オプションの表示方法には、二種類あります。
一括で表示するか、個別に表示するかです。
上記をふまえて、親ページのオプションを取得するときに使用する変数は以下のとおりです。
変数 | 値 |
---|---|
オプションを一括で表示する場合 | |
{$plugin_page_parent_associates[$plugin_page_parent.id].option.[$option.id]} | ページIDが[$plugin_page_parent.id]の親ページのオプションIDが[$option.id]のオプションに登録されている内容 |
オプションを個別に表示する場合 | |
{$plugin_page_parent_associates[$plugin_page_parent.id].option.取得したいオプションID} ※「取得したいオプションID」部分にはオプションIDを代入してください。 例)取得したいオプションIDが「test1」の場合は{$plugin_page_parent_associates[$plugin_page_parent.id].option.test1} |
ページIDが[$plugin_page_parent.id]親ページのオプションIDが「取得したいオプションID」のオプションに登録されている内容 |
説明すると、
{$plugin_page_parent_associates[$plugin_page_parent.id].option.[$option.id]}
こんな感じです。
つまり、
{$親ページのオプションのテーブルを指定して[$親ページのIDを指定して].オプションが.[$どのIDのオプションなのかを指定する]}
こういうことです。
オプションを個別に表示する場合は、[$option.id]部分に、[取得したいオプションID]を書き込みます。
たとえば、オプションID「test1」のオプションを取得したいなら、
{$plugin_page_parent_associates[$plugin_page_parent.id].option.test1}
のようになります。
オプションを一括で表示する場合は、[$option.id]部分を取得するために、オプション格納テーブルの情報を取得する必要があります。
オプション格納テーブルには、そのfreoに登録されているオプションのID、名前などが格納されています。
詳細は、freo公式サイトの機能解説→本体のテーブル構成→オプション格納テーブルのページをご覧下さい。
オプション格納テーブルの情報を取得するには、foreachを使います。
つまり、
<!--{foreach from=$freo.refer.options|smarty:nodefaults item='option'}--> オプションの情報を表示する部分 <!--{/foreach}-->
このようにします。
よって、親ページのオプションを取得する場合は、
<!--{foreach from=$freo.refer.options|smarty:nodefaults item='option'}--> {$plugin_page_parent_associates[$plugin_page_parent.id].option.[$option.id]} <!--{/foreach}-->
このようになります。
親ページのオプション情報を一括で表示するテンプレート編集例
[templates/internals/page]フォルダの[default.html]の親ページの情報を表示したい部分に以下の通り加筆する。
<h3>親ページ</h3> <div class="content"> <dl> <dt><a href="{$freo.core.http_file}/page/{$plugin_page_parent.id}">{$plugin_page_parent.title}</a></dt> <dd> <!--{if $plugin_page_parent_associates[$plugin_page_parent.id].option}--> <table summary="オプション"> <!--{foreach from=$freo.refer.options|smarty:nodefaults item='option'}--> <!--{if $plugin_page_parent_associates[$plugin_page_parent.id].option[$option.id]}--> <tr> <td>{$option.name}</td> <td> <!--{if $option.type == 'file'}--><a href="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}page_options/{$plugin_page_parent.id}/{$option.id}/{$plugin_page_parent_associates[$plugin_page_parent.id].option[$option.id]}">{$plugin_page_parent_associates[$plugin_page_parent.id].option[$option.id]}</a> <!--{else}-->{$plugin_page_parent_associates[$plugin_page_parent.id].option[$option.id]|nl2br} <!--{/if}--> </td> </tr> <!--{/if}--> <!--{/foreach}--> </table> <!--{/if}--> </dd> </dl> </div>
解説
<h3>親ページ</h3> <div class="content"> <dl> <dt><a href="{freo設置URL}/page/{親ページのID}">{親ページのタイトル}</a></dt> <dd> <!--{もし親ページにオプションがついてたらここから}--> <table summary="オプション"> <!--{freoに登録されているオプションをoptionとして繰り返して表示するここから}--> <!--{もしページID[$plugin_page_parent.id]の親ページのオプションID[$option.id]のオプションに情報が登録されていたらここから}--> <tr> <td>{オプション名}</td> <td> <!--{もしオプションの種類がファイルアップロードだったらここから}--><a href="freo設置URL}{filesディレクトリ}page_options/{親ページのページID}/{オプションID}/{親ページ[$plugin_page_parent.id]のオプションID[$option.id]に登録されているファイル名}">{親ページ[$plugin_page_parent.id]のオプションID[$option.id]に登録されているファイル名}</a> <!--{そうじゃなければ}-->{親ページ[$plugin_page_parent.id]のオプションID[$option.id]に登録されている情報|改行を<br />にして表示する} <!--{もしオプションの種類がファイルアップロードだったらここまで}--> </td> </tr> <!--{もしページID[$plugin_page_parent.id]の親ページのオプションID[$option.id]のオプションに情報が登録されていたらここまで}--> <!--{freoに登録されているオプションをoptionとして繰り返して表示するここまで}--> </table> <!--{もし親ページにオプションがついてたらここまで}--> </dd> </dl> </div>
親ページのオプション情報を個別に表示するテンプレート編集例
オプションID「test1」「test2」「test3」が登録されている場合を解説します。
ちなみに、それぞれの種類は
test1…一行入力
test2…複数行入力
test3…アップロード
とします。
[templates/internals/page]フォルダの[default.html]の親ページプラグイン使用部分を以下の通り編集する。
<h3>親ページ</h3> <div class="content"> <dl> <dt><a href="{$freo.core.http_file}/page/{$plugin_page_parent.id}">{$plugin_page_parent.title}</a></dt> <dd> <table summary="オプション"> <!--{if $plugin_page_parent_associates[$plugin_page_parent.id].option}--> <tr> <th>{$freo.refer.options.test1.name}</th> <td>{$plugin_page_parent_associates[$plugin_page_parent.id].option.test1}</td> </tr> <tr> <th>{$freo.refer.options.test2.name}</th> <td>{$plugin_page_parent_associates[$plugin_page_parent.id].option.test2|nl2br}</td> </tr> <tr> <th>{$freo.refer.options.test3.name}</th> <td><a href="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}page_options/{$plugin_page_parent.id}/test3/{$plugin_page_parent_associates[$plugin_page_parent.id].option.test3}">{$plugin_page_parent_associates[$plugin_page_parent.id].option.test3}</a></td> </tr> <!--{/if}--> </table> </dd> </dl> </div>
解説)
<h3>親ページ</h3> <div class="content"> <dl> <dt><a href="{freo設置URL}/page/{親ページのID}">{親ページのタイトル}</a></dt> <dd> <table summary="オプション"> <!--{もし親ページにオプションが登録されてたらここから}--> <tr> <th>{オプションID「test1」のオプション名}</th> <td>{オプションID「test1」に登録されている内容}</td> </tr> <tr> <th>{オプションID「test2」のオプション名}</th> <td>{オプションID「test2」に登録されている内容|改行を<br />として表示する}</td> </tr> <tr> <th>{オプションID「test3」のオプション名}</th> <td><a href="{freo設置アドレス}{filesディレクトリの場所}page_options/{親ページのページID}/test3/{親ページのオプションID「test3」のファイル名}">{親ページのオプションID「test3」のファイル名}</a></td> </tr> <!--{もし親ページにオプションが登録されてたらここまで}--> </table> </dd> </dl> </div>
freo公式サイトの各機能の解説から「オプションを個別に表示する」を参考にしてください。