I’m trying to figure out a way to use filters to remove the last post from a certain tag from rendering. I figured out a way to remove it from a single index page, but now I also need to remove that from tag archives and related posts.
So in the loop I’ve helped myself with the {{#if@first}} element, but the problem there is that it seems to break with pagination and removes that post on every page /n - any ideas?
Is there a similar helper as well for the tag helpers such as the related posts widget, the next/older posts?
{{#next_post in="primary_tag"}}
{{#has tag=“x”}}
{{> "post-card-rel-perf"}}
{{else has tag="tips"}}
{{> "post-card-rel-tip"}}
{{else has tag="blog"}}
{{> "post-card"}}
{{else has tag="getting-started"}}
{{> "post-card"}}
{{else}}
{{> "post-card"}}
{{/has}}
{{/next_post}}
Well, yes, this would apply your code whenever the {{foreach}} is used.
If you want this only on the home page for example then you can do an additional check for context ( {{#is "home"}})
Related posts use the foreach, so you can do the same thing there as well… You can check the docs for any context you are interested in.
You could theoretically fetch the latest post and check if next_post and the latest post have the same id… but it’s a bit overengineered, maybe there is a simpler solution…
What I don’t get is why do you want to hide the latest post from everywhere? Is this a specific post, if yes, then maybe simpler to exclude it by the id, or slug.
I have a special kind of requirement that basically doesn’t let users see the newest post (it’s public, but still paid access). Unfortunately this was the simplest solution without having to constantly manually mark one post to private and the other one to public.