4

よし、私のホームページでニュース項目の 3 つのリストを取り出したいと思います。主要なニュース、注目のニュース、ニュースの見出し。メジャー ニュースの見出しの下に一度に表示される項目は 1 つだけであり、そのようにフラグが付けられた他のエントリは、注目のニュース リストにフィルターで戻されます。

私の問題は、「1 つの」主要なニュース項目の entry_id を取得し、それを特集リストから除外することです。主要なニュース項目が常に最新のニュース項目であるとは限らないため、offset="1" の使用を除外します。

そこで、カスタム フィールド (cf_news_article_type) に基づいてニュースを除外する Stash セットをまとめました。cf_news_article_type は、ユーザーがニュース項目を追加するときに設定する 3 つのラジオ ボタンのリストです。フィールドの値は次のように設定されます。

mj : Major Feature
gf : Featured Article
gn : General article

すべてのタイプから 13 のニュース項目のセットを隠します。

{!-- Bring out all the recent news --}
{exp:channel:entries channel="news" orderby="date" sort="desc" dynamic="no" limit="13" parse="inward" disable="categories|category_fields|member_data|pagination|trackbacks"}
{exp:stash:append_list name='recent_articles'}
    {stash:item_count}{count}{/stash:item_count}
    {stash:item_type}{cf_news_article_type}{/stash:item_type}
    {stash:item_title}{title}{/stash:item_title}
{/exp:stash:append_list}
{/exp:channel:entries}

次に、テンプレートの後半で、主要なニュース項目を取り出します。

<article class="major-feature">
{exp:stash:get_list name="recent_articles" match="#mj#" against="item_type" limit="1" parse_tags="yes"}
    {sn_news_story}
{/exp:stash:get_list}
</article>

ここで大きな問題があります: 注目のニュース リストからその 1 つの主要なニュース アイテムを除外し、注目の Stash リストを取得したときに他のアイテムに「mj」のフラグを付けたままにするにはどうすればよいでしょうか?

<section class="featured-stories">
<h1>Featured stories</h1>
{exp:stash:get_list name="recent_articles" match="#(mj|gf)#" against="item_type" limit="3" parse_tags="yes"}
    {sn_news_story}
{/exp:stash:get_list}
</section>

それから、私の見出しでは、これら 2 つのリストに示されている主要なニュース項目をすべて除外したいと思いますが、それについては別の記事で取り組もうと思います。

これは、そのようなことを行うための正しいアプローチですか? どんな助けでも大歓迎です。

4

1 に答える 1

1

注目のニュース記事を個別に隠してみませんか?例えば:

{!-- find just the featured article --}
{exp:channel:entries channel="news" orderby="date" sort="desc" dynamic="no" search:cf_news_article_type="mj" limit="1" parse="inward"}
    {exp:stash:append_list name='featured_article'}
        {stash:item_count}{count}{/stash:item_count}
        {stash:item_type}{cf_news_article_type}{/stash:item_type}
        {stash:item_title}{title}{/stash:item_title}
    {/exp:stash:append_list}
    {exp:stash:set_value name="featured_article_id" value="{entry_id}" type="snippet"}
{/exp:channel:entries}

次に、残りのニュースを見つけたら、すでに隠しておいた注目の記事を無視してください。

{!-- find the rest of the news --}
{exp:channel:entries channel="news" orderby="date" sort="desc" dynamic="no" limit="12" entry_id="not {featured_article_id}" parse="inward"}
    {exp:stash:append_list name='recent_articles'}
        {stash:item_count}{count}{/stash:item_count}
        {stash:item_type}{cf_news_article_type}{/stash:item_type}
        {stash:item_title}{title}{/stash:item_title}
    {/exp:stash:append_list}
{/exp:channel:entries}

(で解析順序の問題が発生するかどうかはわかりませんが{featured_article_id}、発生する場合は回避策があるはずです)

または、注目のニュース記事がすべてリストの一番上にあることを気にしない場合は、を使用してからorderby="cf_news_article_type|date"、を使用limit=""offset=""て最初のニュース記事をリストから削除することもできます。

更新:これを逆に行うこともできます。リストを取得するときにentry_idを確認してください。

<article class="major-feature">
    {exp:stash:get_list name="recent_articles" match="#mj#" against="item_type" limit="1" parse_tags="yes"}
        {exp:stash:set_value name="featured_article_id" value="{entry_id}" type="snippet"}
        {sn_news_story}
    {/exp:stash:get_list}
</article> 

<section class="featured-stories">
    <h1>Featured stories</h1>
    {exp:stash:get_list name="recent_articles" match="#(mj|gf)#" against="item_type" limit="3" parse_tags="yes"}
        {if "{entry_id}" != "{featured_article_id}"}
            {sn_news_story}
        {/if}
    {/exp:stash:get_list}
</section>
于 2012-10-31T22:21:30.087 に答える