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

> Entry >freo>freoTips>プラグイン系TIPS> エントリーカテゴリー表示プラグインで特定のカテゴリー以下のエントリーのみ表示する方法

【freo】【freoTips】【プラグイン系TIPS】エントリーカテゴリー表示プラグインで特定のカテゴリー以下のエントリーのみ表示する方法

当サイトで配布しているエントリーカテゴリー表示プラグインを利用して、特定のカテゴリー以下のエントリーのみ表示する方法です。

エントリーカテゴリー表示プラグインは、カテゴリーごとにエントリーを一覧表示するプラグインです。
特定のカテゴリーのエントリーのみ一覧表示する方法は以下のとおりです。

エントリーカテゴリー表示プラグインを他の画面でも利用できるようにする

エントリーカテゴリー表示プラグインは、デフォルトの状態だと、「デフォルト画面」「エントリー画面」「カテゴリー画面」「記事個別表示画面(VIEW画面)」のみで利用できますが、これを他の画面(例えばページ画面)などで利用するようにするには、プラグインの編集が必要です。

[freo/libs/freo/plugins]フォルダ内のconfig.entry_category.phpのdisplayファイルの読み込み設定を編集してください。

詳しくは↓を参照してください。

freo:プラグインを色々なページに表示する

カテゴリーごとのエントリー件数を他の画面でも表示できるようにする

カテゴリーごとのエントリー件数はfreoにデフォルトで導入されている「カテゴリー記事数表示プラグイン」を利用していますが、これを他の画面(例えばページ画面)などで利用するようにするには、プラグインの編集が必要です。

[freo/libs/freo/plugins]フォルダ内のconfig.category_count.phpのdisplayファイルの読み込み設定を編集してください。

詳しくは↓を参照してください。

freo:プラグインを色々なページに表示する

特定のカテゴリーのエントリーのみ一覧表示する方法

  1. エントリーカテゴリー表示プラグインを導入する。
  2. 特定のカテゴリーのエントリーのみ表示したい画面のテンプレーの、エントリーを表示したい箇所に下記の通り加筆する。
    {assign var="pid" value='表示させたいカテゴリーID'}
    <!--{foreach from=$freo.refer.categories|smarty:nodefaults item='refer_category'}-->
        <!--{if $refer_category.id == $pid and $refer_category.display == 'publish'}-->
            <!--{php}if (!$flag) :{/php}-->
            <ul>
            <!--{php}endif;{/php}-->
                <li>
                    <a href="{$freo.core.http_file}/category/{$refer_category.id}">{$refer_category.name}</a>({$plugin_category_counts[$refer_category.id]|default:0})
                        <ul>
                            <!--{foreach from=$plugin_entry_categories|smarty:nodefaults item='entry'}-->
                                <!--{foreach from=$plugin_entry_category_associates[$entry.id].category|smarty:nodefaults key='entry_category' item='entry_category' name='loop'}-->
                                    <!--{if $refer_category.id == $freo.refer.categories[$entry_category].id}-->
                                        <li><a href="{$freo.core.http_file}/view/{if $entry.code}{$entry.code}{else}{$entry.id}{/if}">{$entry.title}</a><!--{if $entry.restriction == 'user' and !$entry_category_securities[$entry.id]}--><span class="attention">(このエントリーは、登録ユーザーのみに公開されています。)</span><!--{elseif $entry.restriction == 'group' and !$entry_category_securities[$entry.id]}--><span class="attention">(このエントリーは、一部のグループのみに公開されています。)</span><!--{elseif $entry.restriction == 'password' and !$entry_category_securities[$entry.id]}--><span class="attention">(このエントリーは、パスワードで認証した人のみに公開されています。)</span><!--{/if}--></li>
                                    <!--{/if}-->
                                <!--{/foreach}-->
                            <!--{/foreach}-->
                        </ul>
                    <!--{assign var="pid" value=$refer_category.id}-->
                    {include file='entry_category.html'}
                    <!--{assign var="pid" value=$refer_category.pid}-->
                </li>
            <!--{php}$flag = 1;{/php}-->
        <!--{/if}-->
    <!--{foreachelse}-->
        <ul>
            <li>カテゴリーが登録されていません。</li>
        </ul>
    <!--{/foreach}-->
    <!--{php}if ($flag) :{/php}--></ul><!--{php}endif;{/php}-->
    
  3. 編集したテンプレートをアップロードする。

サンプルとして、ページIDが「novel」のページにカテゴリーIDが「novel」のエントリーのみ表示する方法を説明します。
上記の例の場合は、編集するテンプレートは[freo/templates/internals/pages/novel.html]またはnovel.htmlがない場合は[freo/templates/internals/pages/default.html]です。
追加するソースは、

{assign var="pid" value='novel'}
<!--{foreach from=$freo.refer.categories|smarty:nodefaults item='refer_category'}-->
    <!--{if $refer_category.id == $pid and $refer_category.display == 'publish'}-->
        <!--{php}if (!$flag) :{/php}-->
        <ul>
        <!--{php}endif;{/php}-->
            <li>
                <a href="{$freo.core.http_file}/category/{$refer_category.id}">{$refer_category.name}</a>({$plugin_category_counts[$refer_category.id]|default:0})
                    <ul>
                        <!--{foreach from=$plugin_entry_categories|smarty:nodefaults item='entry'}-->
                            <!--{foreach from=$plugin_entry_category_associates[$entry.id].category|smarty:nodefaults key='entry_category' item='entry_category' name='loop'}-->
                                <!--{if $refer_category.id == $freo.refer.categories[$entry_category].id}-->
                                    <li><a href="{$freo.core.http_file}/view/{if $entry.code}{$entry.code}{else}{$entry.id}{/if}">{$entry.title}</a><!--{if $entry.restriction == 'user' and !$entry_category_securities[$entry.id]}--><span class="attention">(このエントリーは、登録ユーザーのみに公開されています。)</span><!--{elseif $entry.restriction == 'group' and !$entry_category_securities[$entry.id]}--><span class="attention">(このエントリーは、一部のグループのみに公開されています。)</span><!--{elseif $entry.restriction == 'password' and !$entry_category_securities[$entry.id]}--><span class="attention">(このエントリーは、パスワードで認証した人のみに公開されています。)</span><!--{/if}--></li>
                                <!--{/if}-->
                            <!--{/foreach}-->
                        <!--{/foreach}-->
                    </ul>
                <!--{assign var="pid" value=$refer_category.id}-->
                {include file='entry_category.html'}
                <!--{assign var="pid" value=$refer_category.pid}-->
            </li>
        <!--{php}$flag = 1;{/php}-->
    <!--{/if}-->
<!--{foreachelse}-->
    <ul>
        <li>カテゴリーが登録されていません。</li>
    </ul>
<!--{/foreach}-->
<!--{php}if ($flag) :{/php}--></ul><!--{php}endif;{/php}-->

です。

更新履歴

  • 2016/06/10 ソースをエントリーカテゴリー表示プラグイン(ver.1_1_1)に対応しました。

ページ移動

関連記事

ユーティリティ

Twitter

ページ上部へ