• 虹色ミツバチ
  • freoカスタマイズメモ、テンプレート・プラグイン配布/officeTIPS
検索プラグイン
虹色ミツバチ

> Entry >freo>freoTips>freo変数一覧> 子ページ表示プラグインで子ページのオプションを表示する方法

【freo】【freoTips】【freo変数一覧】子ページ表示プラグインで子ページのオプションを表示する方法

freoにはページメニュー表示プラグインがデフォルトで備わっています。
freoには子ページ表示プラグインがデフォルトで備わっているので、あるページの子ページの情報を取得することができます。

【関連リンク】
32877|子ページ表示プラグインで子ページの情報を取得する方法

下記に、子ページのオプションの情報を取得する方法を紹介します。

子ページのオプション情報を表示する方法

子ページの情報についての解説

あるページの子ページは、複数存在する可能性があります。
よって、子ページの情報を格納するテーブルは、多次元配列になっています。
よって、子ページの情報を取り出すときには、foreachを利用しなければなりません。

子ページの情報は、「$plugin_page_childs」というテーブルに格納されています。
「$plugin_page_childs」テーブルの情報を表示したいときは、foreachしなければなりません。

とにかく、子ページの情報を表示したいなら、下記の通りにしなければならないってことです。

<!--{foreach from=$plugin_page_childs|smarty:nodefaults item='plugin_page_child'}-->

子ページの情報を表示したい部分

<!--{/foreach}-->

上記のように、子ページの情報を表示したい箇所は、<!--{foreach from=$plugin_page_childs|smarty:nodefaults ~中略}-->と<!--{/foreach}-->で挟みます。
foreachの中に入れないで変数だけ書いても、子ページの情報は表示されませんので注意して下さい。

子ページのオプションのとりかたについての解説

オプションの表示方法には、二種類あります。
一括で表示するか、個別に表示するかです。

上記をふまえて、子ページのオプションを取得するときに使用する変数は以下のとおりです。

変数
オプションを一括で表示する場合
{$plugin_page_child_associates[$plugin_page_child.id].option.[$option.id]} ページIDが[$plugin_page_child.id]の子ページのオプションIDが[$option.id]のオプションに登録されている内容
オプションを個別に表示する場合
{$plugin_page_child_associates[$plugin_page_child.id].option.取得したいオプションID}
※「取得したいオプションID」部分にはオプションIDを代入してください。
例)取得したいオプションIDが「test1」の場合は{$plugin_page_child_associates[$plugin_page_child.id].option.test1}
ページIDが[$plugin_page_child.id]子ページのオプションIDが「取得したいオプションID」のオプションに登録されている内容

説明すると、

{$plugin_page_child_associates[$plugin_page_child.id].option.[$option.id]}

こんな感じです。
つまり、

{$子ページのオプションのテーブルを指定して[$子ページのIDを指定して].オプションが.[$どのIDのオプションなのかを指定する]}

こういうことです。

しかし、上の変数だけを書いても子ページのオプションの情報は取得できません。

オプションを一括で取得する場合も、個別に取得する場合も、共通しているのは、[$plugin_page_sibiling.id]=[$子ページのID]を指定するために、やはり、<!--{foreach from=$plugin_page_childs|smarty:nodefaults ~中略}-->と<!--{/foreach}-->で挟む必要があるということです。

オプションを個別に表示する場合は、[$option.id]部分に、[取得したいオプションID]を書き込みます
たとえば、オプションID「test1」のオプションを取得したいなら、

<!--{foreach from=$plugin_page_childs|smarty:nodefaults item='plugin_page_child'}-->

{$plugin_page_child_associates[$plugin_page_child.id].option.test1}

<!--{/foreach}-->

のようになります。

オプションを一括で表示する場合は、[$option.id]部分を取得するために、オプション格納テーブルの情報を取得する必要があります。

オプション格納テーブルには、そのfreoに登録されているオプションのID、名前などが格納されています。
詳細は、freo公式サイトの機能解説→本体のテーブル構成→オプション格納テーブルのページをご覧下さい。

オプション格納テーブルの情報を取得するには、foreachを使います。
つまり、

<!--{foreach from=$freo.refer.options|smarty:nodefaults item='option'}-->

オプションの情報を表示する部分

<!--{/foreach}-->

このようにします。

よって、子ページのオプションを取得する場合は、

<!--{foreach from=$plugin_page_childs|smarty:nodefaults item='plugin_page_child'}-->
   <!--{foreach from=$freo.refer.options|smarty:nodefaults item='option'}-->

       {$plugin_page_child_associates[$plugin_page_child.id].option.[$option.id]}

   <!--{/foreach}-->
<!--{/foreach}-->

 このようになります。

子ページのオプション情報を一括で表示するテンプレート編集例

[templates/internals/page]フォルダの[default.html]の子ページプラグイン使用部分を以下の通り編集する。

<!--{if $plugin_page_childs|smarty:nodefaults}-->
    <h3>目次</h3>
        <ul>
            <!--{foreach from=$plugin_page_childs|smarty:nodefaults item='plugin_page_child'}-->
                <li><a href="{$freo.core.http_file}/page/{$plugin_page_child.id}">{$plugin_page_child.title}</a>
                <!--{if $plugin_page_child_associates[$plugin_page_child.id].option}-->
                    <dl>
                        <!--{foreach from=$freo.refer.options|smarty:nodefaults item='option'}-->
                            <!--{if $plugin_page_child_associates[$plugin_page_child.id].option[$option.id]}-->
                                <dt>{$option.name}</dt>
                                <dd>
                                    <!--{if $option.type == 'file'}--><a href="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}page_options/{$plugin_page_child.id}/{$option.id}/{$plugin_page_child_associates[$plugin_page_child.id].option[$option.id]}">{$plugin_page_child_associates[$plugin_page_child.id].option[$option.id]}</a>
                                    <!--{else}-->{$plugin_page_child_associates[$plugin_page_child.id].option[$option.id]|nl2br}
                                    <!--{/if}-->
                                </dd>
                            <!--{/if}-->
                        <!--{/foreach}-->
                    </dl>
                <!--{/if}-->
                </li>
            <!--{/foreach}-->
        </ul>
<!--{/if}-->

解説

<!--{もし子ページがあったらここから}-->
    <h3>目次</h3>
        <ul>
            <!--{子ページを[$plugin_page_child]として繰り返して表示するここから}-->
                <li><a href="{freo設置URL}/page/{子ページのID}">{子ページのタイトル}</a>
                <!--{もし子ページにオプションがついてたらここから}-->
                    <dl>
                        <!--{freoに登録されているオプションを[$option]として繰り返して表示するここから}-->
                            <!--{もし子ページ[$plugin_page_child.id]のオプションIDが[$option.id]のオプションに情報が登録されていたらここから}-->
                                <dt>{オプションの名前}</dt>
                                <dd>
                                    <!--{もしオプションの種類がファイルアップロードだったらここから}--><a href="{freo設置URL}{freoのファイル設置フォルダ}page_options/{子ページのID}/{オプションのID}/{子ページ[$plugin_page_child.id]のオプションIDが[$option.id]のオプションに登録されている情報=ファイル名}">{子ページ[$plugin_page_child.id]のオプションIDが[$option.id]のオプションに登録されている情報=ファイル名}</a>
                                    <!--{そうじゃなければ}-->{子ページ[$plugin_page_child.id]のオプションIDが[$option.id]のオプションに登録されている情報|改行を<br />として表示する}
                                    <!--{もしオプションの種類がファイルアップロードだったらここまで}-->
                                </dd>
                            <!--{もし子ページ[$plugin_page_child.id]のオプションIDが[$option.id]のオプションに情報が登録されていたらここまで}-->
                        <!--{freoに登録されているオプションを繰り返して表示するここまで}-->
                    </dl>
                <!--{もし子ページにオプションがついてたらここまで}-->
                </li>
            <!--{子ページを繰り返して表示するここまで}-->
        </ul>
<!--{もし子ページがあったらここまで}-->

子ページのオプション情報を個別に表示するテンプレート編集例

オプションID「test1」「test2」「test3」が登録されている場合を解説します。
ちなみに、それぞれの種類は
test1…一行入力
test2…複数行入力
test3…アップロード
とします。

[templates/internals/page]フォルダの[default.html]の子ページプラグイン使用部分を以下の通り編集する。

 <!--{if $plugin_page_childs|smarty:nodefaults}-->
<h3>目次</h3>
<ul>
<!--{foreach from=$plugin_page_childs|smarty:nodefaults item='plugin_page_child'}-->
   <li><a href="{$freo.core.http_file}/page/{$plugin_page_child.id}">{$plugin_page_child.title}</a>
      <!--{if $plugin_page_child_associates[$plugin_page_child.id].option}-->
         <table summary="オプション">
         <tr>
             <th>{$freo.refer.options.test1.name}</th>
             <td>{$plugin_page_child_associates[$plugin_page_child.id].option.test1}</td>
         </tr>
         <tr>
             <th>{$freo.refer.options.test2.name}</th>
             <td>{$plugin_page_child_associates[$plugin_page_child.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_child.id}/test3/{$plugin_page_child_associates[$plugin_page_child.id].option.test3}">{$plugin_page_child_associates[$plugin_page_child.id].option.test3}</a></td>
         </tr>
         </table>
      <!--{/if}-->
   </li>
<!--{/foreach}-->
</ul>
<!--{/if}-->

解説)

 <!--{もし子ページがあったらここから}-->
<h3>目次</h3>
<ul>
<!--{子ページを繰り返して表示するここから}-->
   <li><子ページのURLへリンクここから>子ページのタイトル<子ページのURLへリンクここまで>
      <!--{もし子ページ[$plugin_page_child]にオプションが利用されていたらここから}-->
         <table summary="オプション">
         <tr>
             <th>{オプションID「test1」のオプション名}</th>
             <td>{子ページ[$plugin_page_child]に登録されてるオプションID「test1」の内容}</td>
         </tr>
         <tr>
             <th>{オプションID「test2」のオプション名}</th>
             <td>{子ページ[$plugin_page_child]に登録されてるオプションID「test2」の内容|改行は<br />に変換}</td>
         </tr>
         <tr>
             <th>{オプションID「test3」のオプション名}</th>
             <td><子ページ[$plugin_page_child]に登録されてるオプションID「test3」ファイルへのリンク>{子ページ[$plugin_page_child]に登録されてるオプションID「test3」の内容}</a></td>
         </tr>
         </table>
      <!--{もし子ページ[$plugin_page_child]にオプションが利用されていたらここまで}-->
   </li>
<!--{子ページを繰り返して表示するここまで}-->
</ul>
<もし子ページがあったらここまで>

freo公式サイトの各機能の解説から「オプションを個別に表示する」を参考にしてください。

ページ移動

関連記事

ユーティリティ

Twitter

ページ上部へ