This one's got me.
I'm using Stash to capture a list of entries into a set_list. I want to get this list in two different areas on the page with different categories. If I were simply trying to display 2 different categories, match/against would work. However, what I'm trying to do seems to be a little more complicated. Here's what I want:
- In the first get_list, I want to show entries from all but one category.
- In the second get_list, I want to show entries from the the single category I excluded in the first list
The exact scenario is that I would like one list to show all articles, and the other list to show only announcements.
Here's what I'm starting off with:
{!-- Articles --}
{exp:stash:set_list name="articles" parse_tags="yes"}
{exp:channel:entries
channel="news"
dynamic="no"
orderby="sticky|entry_date"
sort="desc|desc"
sort_type="numeric|numeric"
disable="pagination|member_data|category_fields"
}
{stash:sticky}{sticky}{/stash:sticky}
{stash:title}{title}{/stash:title}
{stash:summary}{article_summary}{/stash:summary}
{stash:date}{entry_date}{/stash:date}
{stash:url}{page_url}{/stash:url}
{stash:image}{article_featured_image}{/stash:image}
{!-- Get the category_id so we can match against them --}
{stash:category_id}{categories}{category_id}{/categories}{/stash:category_id}
{/exp:channel:entries}
{/exp:stash:set_list}
So, that gives me my list of all articles. For my second list, it's as simple as using match/against to only show announcments:
{exp:stash:get_list name="articles" match="#^13#" against="category_id"}
<article>
<p><a href="{url}"><i class="ss-icon ss-newspaper"></i> <span class="meta">{date format="%M %d, %Y"}</span> {title}</a></p>
</article>
{/exp:stash:get_list}
It's the first list where I'm stumped. How do I capture all entries except for those in category 13 without having to make another channel entries call?
I know I could just create 2 separate set_lists with 2 separate channel entry calls. One which has category="not 13" and another with category="13".
I also thought I could wrap 2 set_lists in the {cateogries} tag and, again use show="13" and show="not 13", but I don't see a way to do that without repeating my stash variable setters.
How do I keep this at a single channel entry call and keep it DRY?
Update:
romans-8-31-39 pointed out a feature I didn't know existed, which was to NOT match a pattern when filtering a list. That answer is technically correct. When I went to implement that, I realized I'm already using match/against on my first list to match against sticky entries.
Would this be a use case for the stash technique outlined here? I'm having a hard time wrapping my head around the technique.
{exp:stash:get_list name="articles" match="#^y$#" against="sticky"}