Log in Sign up

Exclude posts with specific tags?

Would it be possible to show all entries excluding posts with a specific tag?


a year ago, 7 replies   developers   Edit question

Absolutely! You will first want to fork an editable version of your template if you haven't already.

You will notice that lists of blog posts are rendered in your template's entries.html file and archives.html file, among other template files. These lists look something like:

{{#entries}}
   ... <a href="{{{url}}}">{{title}}</a>
{{/entries}}

To filter posts with the specific tag Apple out of these lists, you can use an inverted section, which looks like this:

{{^tagged.apple}}
...
{{/tagged.apple}}

The full example, using an inverted section to remove posts tagged Apple from your list of entries will look something like this:

{{#entries}}
{{^tagged.apple}}
   ... <a href="{{{url}}}">{{title}}</a>
{{/tagged.apple}}
{{/entries}}

Please let me know if you have any questions about implementing this! I'm always willing to answer over email if you have something you'd rather not share publicly, too.

Answered 4 years ago · Edit answer

Apologies for replying to a 2 year old post.

I'm trying to achieve this with the Photo template, where I'd like to not display posts tagged "Blog" on the main page. Adding the above code to the grid_bookshelf.html page (which is where the {{entries}} blog lives in this template) doesn't hide the posts, and causes some weird display issues with the posts I don't want hidden.

Is there another method to achieve this effect, or maybe something I'm missing/not understanding about the way the Photo template builds the main page?

Thanks for any help you can give me!

Answered a year ago · Edit answer

If you're using the bookshelf grid on the Photo template and you'd like to remove posts tagged 'Apple', you'd insert a new line with the following below line 137:

{{^tagged.apple}}

And a new line with the following below line 179:

{{/tagged.apple}}

Does that make sense? Please let me know if you have any questions

Answered a year ago · Edit answer

Hello! Quick follow-up question. I successfully excluded posts with a specific tag from my entries.html page (using a modified version of the Blog template). However, it seems like the hidden posts still count toward the "Posts per page" limit, so if there's a bunch of hidden posts, there can be situations where only 1 'real' post appears.

Is there a way to prevent this behavior so the counter for "Posts per page" only counts visible posts? It's also entirely possible I'm missing something here in my approach.

Thanks!

Answered a year ago · Edit answer

It's not possible right now but this is something I plan to make possible – if you want me to email you when it's ready please contact us

Answered a year ago · Edit answer

Is there an update to this? I have the same problem in that from a specific number of "excluded" tagged posts onward the untagged, "normal" content on the front page disappears and is pushed to the next page(s).

I am not sure where the counting takes place (I assume somewhere in the JS), but couldn't specific tags not be sent to the compile engine to be excluded from counting?

Answered a year ago · Edit answer

The problem is that the filtering happens after the pagination. I need to build a more complex query into the back end. If you would like to be notified when this is added via email, please contact us

Answered a year ago · Edit answer