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

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

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

freo公式サイトで、新着ページ表示プラグインが配布されています。
これは、新規に登録されたページ一覧を表示するプラグインです。

【関連リンク】
32877|新着ページ表示プラグインで取得できる情報

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

新着ページのオプション情報を取得する方法

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

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

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

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

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

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

<!--{/foreach}-->

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

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

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

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

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

説明すると、

{$plugin_page_recently_associates[$plugin_page_recently.id].option.[$option.id]}

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

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

こういうことです。

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

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

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

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

{$plugin_page_recently_associates[$plugin_page_recently.id].option.test1}

<!--{/foreach}-->

のようになります。

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

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

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

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

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

<!--{/foreach}-->

このようにします。

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

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

       {$plugin_page_recently_associates[$plugin_page_recently.id].option.[$option.id]}

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

 このようになります。

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

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

<h3>新着ページ</h3>
<div class="content">
    <dl>
        <!--{foreach from=$plugin_page_recentries|smarty:nodefaults item='plugin_page_recently'}-->
        <dt><a href="{$freo.core.http_file}/page/{$plugin_page_recently.id}">{$plugin_page_recently.title}</a></dt>
        <dd>
            <table summary="オプション">
                <tr>
                    <td>投稿時間</td>
                    <td>{$plugin_page_recently.datetime|date_format:'%Y/%m/%d %H:%M'}</td>
                </tr>
                <!--{if $plugin_page_recently_associates[$plugin_page_recently.id].option}-->
                <!--{foreach from=$freo.refer.options|smarty:nodefaults item='option'}-->
                <!--{if $plugin_page_recently_associates[$plugin_page_recently.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_recently.id}/{$option.id}/{$plugin_page_recently_associates[$plugin_page_recently.id].option[$option.id]}">{$plugin_page_recently_associates[$plugin_page_recently.id].option[$option.id]}</a>
                            <!--{else}-->{$plugin_page_recently_associates[$plugin_page_recently.id].option[$option.id]|nl2br}
                            <!--{/if}-->
                        </td>
                    </tr>
                <!--{/if}-->
                <!--{/foreach}-->
                <!--{/if}-->
            </table>
        </dd>
        <!--{/foreach}-->
    </dl>
</div>
解説
<h3>新着ページ</h3>
<div class="content">
    <dl>
        <!--{新着ページをplugin_page_recentlyとして繰り返して表示するここから}-->
        <dt><a href="{freo設置URL}/page/{新着ページのID}">{新着ページのタイトル}</a></dt>
        <dd>
            <table summary="オプション">
                <tr>
                    <td>投稿時間</td>
                    <td>{新着ページの投稿時間を'%Y/%m/%d %H:%M'と整形して表示する}</td>
                </tr>
                <!--{もし新着ページにオプションがついてたらここから}-->
                <!--{freoに登録されているオプションをoptionとして繰り返して表示するここから}-->
                <!--{もしページID[$plugin_page_recently.id]の新着ページのオプションID[$option.id]のオプションに情報が登録されていたらここから}-->
                    <tr>
                        <td>{オプション名}</td>
                        <td>
                            <!--{もしオプションの種類がファイルアップロードだったらここから}--><a href="freo設置URL}{filesディレクトリ}page_options/{新着ページのページID}/{オプションID}/{新着ページ[$plugin_page_recently.id]のオプションID[$option.id]に登録されているファイル名}">{新着ページ[$plugin_page_recently.id]のオプションID[$option.id]に登録されているファイル名}</a>
                            <!--{そうじゃなければ}-->{新着ページ[$plugin_page_recently.id]のオプションID[$option.id]に登録されている情報|改行を<br />にして表示する}
                            <!--{もしオプションの種類がファイルアップロードだったらここまで}-->
                        </td>
                    </tr>
                <!--{もしページID[$plugin_page_recently.id]の新着ページのオプションID[$option.id]のオプションに情報が登録されていたらここまで}-->
                <!--{freoに登録されているオプションをoptionとして繰り返して表示するここまで}-->
                <!--{もし新着ページにオプションがついてたらここまで}-->
            </table>
        </dd>
        <!--{新着ページをplugin_page_recentlyとして繰り返して表示するここまで}-->
    </dl>
</div>

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

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

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

<h3>新着ページ</h3>
<div class="content">
    <dl>
        <!--{foreach from=$plugin_page_recentries|smarty:nodefaults item='plugin_page_recently'}-->
        <dt><a href="{$freo.core.http_file}/page/{$plugin_page_recently.id}">{$plugin_page_recently.title}</a></dt>
        <dd>
            <table summary="オプション">
                <tr>
                    <td>投稿時間</td>
                    <td>{$plugin_page_recently.datetime|date_format:'%Y/%m/%d %H:%M'}</td>
                </tr>
                <!--{if $plugin_page_recently_associates[$plugin_page_recently.id].option}-->
                <tr>
                    <th>{$freo.refer.options.test1.name}</th>
                    <td>{$plugin_page_recently_associates[$plugin_page_recently.id].option.test1}</td>
                </tr>
                <tr>
                    <th>{$freo.refer.options.test2.name}</th>
                    <td>{$plugin_page_recently_associates[$plugin_page_recently.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_recently.id}/test3/{$plugin_page_recently_associates[$plugin_page_recently.id].option.test3}">{$plugin_page_recently_associates[$plugin_page_recently.id].option.test3}</a></td>
                </tr>
                <!--{/if}-->
            </table>
        </dd>
        <!--{/foreach}-->
    </dl>
</div>
解説
<h3>新着ページ</h3>
<div class="content">
    <dl>
        <!--{新着ページをplugin_page_recentlyとして繰り返して表示するここから}-->
        <dt><a href="{freo設置URL}/page/{新着ページのID}">{新着ページのタイトル}</a></dt>
        <dd>
            <table summary="オプション">
                <tr>
                    <td>投稿時間</td>
                    <td>{新着ページの投稿時間を'%Y/%m/%d %H:%M'と整形して表示する}</td>
                </tr>
                <!--{もし新着ページにオプションがついてたらここから}-->
                <tr>
                    <th>{オプションID「test1」のオプション名}</th>
                    <td>{新着ページ[$plugin_page_recently.id]のオプションID「test1」のオプションに登録されている情報}</td>
                </tr>
                <tr>
                    <th>{オプションID「test2」のオプション名}</th>
                    <td>{新着ページ[$plugin_page_recently.id]のオプションID「test2」のオプションに登録されている情報|改行を<br />にして表示する}</td>
                </tr>
                <tr>
                    <th>{オプションID「test3」のオプション名}</th>
                    <td><a href="{freo設置URL}{filesディレクトリ}page_options/{新着ページのID}/test3/{新着ページ[$plugin_page_recently.id]のオプションID「test3」に登録されているファイル名}">{新着ページ[$plugin_page_recently.id]のオプションID「test3」に登録されているファイル名}</a></td>
                </tr>
                <!--{もし新着ページにオプションがついてたらここまで}-->
            </table>
        </dd>
        <!--{新着ページをplugin_page_recentlyとして繰り返して表示するここまで}-->
    </dl>
</div>

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

ページ移動

関連記事

ページ上部へ