カテゴリに関係なく10件の結果を表示するか、URLのカテゴリ情報に基づいて10件の結果を表示するかのいずれかのニュースページがあります。
私のコードは、URLにカテゴリのURLがあるかどうかを調べています。そうであれば、カテゴリIDを持つクエリを実行してそのカテゴリに結果を限定します。そうでなければ完全なクエリを実行します。
私は自分のロジックをテストしましたが、条件付きのEEクエリは期待どおりに動作していますが、Stashリストを出力すると、そのカテゴリにないエントリの結果が表示されます。
2つの異なるリスト名が必要ですか?
{if segment_2_category_id != ''}
{exp:stash:set_list name="news_list" parse_tags="yes" parse_depth="2"}
{exp:channel:entries channel="news" status="open|featured" orderby="date" sort="desc" limit="10" category="{segment_2_category_id}"}
{stash:item_title}{title}{/stash:item_title}
{stash:item_url}{url_title}{/stash:item_url}
{stash:item_date}{entry_date format="%F %d, %Y "}{/stash:item_date}
{stash:item_copy}{news_content}{/stash:item_copy}
{stash:item_entry_id}{entry_id}{/stash:item_entry_id}
{exp:stash:set_list:nested name="item_media" context="{entry_id}" parse_tags="yes"}
{news_videos_images}
{stash:item_image}{image}{/stash:item_image}
{stash:item_video}{video}{/stash:item_video}
{/news_videos_images}
{/exp:stash:set_list:nested}
{/exp:channel:entries}
{/exp:stash:set_list}
{if:else}
{exp:stash:set_list name="news_list" parse_tags="yes" parse_depth="2"}
{exp:channel:entries channel="news" status="open|featured" orderby="date" sort="desc" limit="10"}
{stash:item_title}{title}{/stash:item_title}
{stash:item_url}{url_title}{/stash:item_url}
{stash:item_date}{entry_date format="%F %d, %Y "}{/stash:item_date}
{stash:item_copy}{news_content}{/stash:item_copy}
{stash:item_entry_id}{entry_id}{/stash:item_entry_id}
{exp:stash:set_list:nested name="item_media" context="{entry_id}" parse_tags="yes"}
{news_videos_images}
{stash:item_image}{image}{/stash:item_image}
{stash:item_video}{video}{/stash:item_video}
{/news_videos_images}
{/exp:stash:set_list:nested}
{/exp:channel:entries}
{/exp:stash:set_list}
{/if}