Exclude a specific entry from the list

Ok, so on my homepage I want to pull out 3 news lists; basic news, news and news. There should be only one item that appears under the heading β€œTop News” at a time, and any other posts marked as such will be filtered back to the list of favorite news.

My problem is to capture the entry_id of the main news event and remove it from the list. The main news item may not always be the last news item, therefore it eliminates the use of offset = "1".

So, I have compiled several Stash sets that filter out news based on a custom field (cf_news_article_type). cf_news_article_type is a list of three radio buttons that the user sets when adding a news article. Field values ​​are configured as follows:

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

I put a set of 13 news from all types:

 {!-- 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} 

Then in my template I pull out the main news material:

 <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> 

Now the big question is: how can I exclude this single main news item from the list of selected news, but save the other items under the β€œmj” flag when I get the list of marked lists?

 <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> 

Then for my headlines, I would like to exclude all the recognized and main news articles that are shown in these two lists, but I will solve this issue in another post, I think.

Is this even the right approach for this? Any help would be greatly appreciated.

+4
source share
1 answer

How about publishing your news article individually? For instance:

 {!-- 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} 

Then, when you find the rest of the news, simply ignore the article you have already hidden:

 {!-- 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} 

(I'm not sure if you run into parsing order problems with {featured_article_id} , but if so, there should be a way around it)

Alternatively, if you don't mind having all your news articles at the top of the list, you can use orderby="cf_news_article_type|date" and then just use limit="" and offset="" to get the first news article from the list.

UPDATE:. You can do this and vice versa, and check entry_id when retrieving the list:

 <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> 
+1
source

Source: https://habr.com/ru/post/1443328/


All Articles