For excluding posts from a certain category on the homepage, I found this. But not sure if I need to add this to layouts/index.html or layouts/_default/list.html. I tried both but got errors. I may have inserted them in the wrong place.
I have managed to get it working, but the other way around. Basically, display posts with specific categories, not exclude them. It should be possible but just can’t think of a simple way.
I did this alteration on the default homepage post listing. My use case is I copy all my Letterboxd reviews to my Micro.blog but I don’t want them to show up on the homepage (because I watch a lot of movies and don’t want them to clog up the view).
It seems to work at first, but it actually only filtered out the first four posts. Once it hits a post that passes the “if not” test, the subsequent Letterboxd reviews show on the page.
<ul id="post-list">
{{ if or .IsHome .Site.Params.paginate_categories }}
{{ $paginator := .Paginate (where .Site.Pages.ByDate.Reverse "Type" "post") }}
{{ $list := $paginator.Pages }}
{{ range $list }}
{{ if not (in .Params.categories "Letterboxd") }}
{{ partial "post-item.html" . }}
{{ end }}
{{ end }}
{{ else }}
{{ $list := where .Site.Pages.ByDate.Reverse "Type" "post" }}
{{ range $list }}
{{ if not (in .Params.categories "Letterboxd") }}
{{ partial "post-item.html" . }}
{{ end }}
{{ end }}
{{ end }}
</ul>
You do not want to filter after paginating or after doing a range. You want to filter out these posts at the first point you’re developing what set of pages are valid for your collection.
Thanks! This works for now. I tried all sorts of different permutations for the previous suggestion and it just doesn’t seem to want to work. It’s a bit of a pain having to jump in and update every time I add a category, and doesn’t work well with putting posts in multiple categories. Would love to see a plug-in that simplifies this.
Hugo’s symdiff function returns the symmetric difference between two collections. That’s just a fancy way to say: “give me the things that are in either of these collections but not in both”.
So, if you have all posts in one collection, $posts, and posts from the category you want to exclude in another collection, $hidden_posts, you can get all posts sans excluded posts with $posts | symdiff $hidden_posts. Something like this:
Nice! Thank you, @sod. Learnt a new thing. This should do what @pratik needs.
Replace line 2 in layouts/index.html with this code block that Sven shared. Place categories that you want to exclude in second line next to slice (for example, dev, tech in the example),
Resurfacing this topic a bit, anyone ever done changes in the theme, to also remove the category and it’s posts from listing in the archives page? I was trying with some of the code provided here, but I could not. I am basically trying to implement an RSS-Club on my MB. Welcome to RSS Club | daverupert.com
You’ll want to edit layouts/_default/list.archivehtml.html using the same technique for the range there I think. The way I do my page is different and more complex, but I’m 95% sure that template (which is a default template) is where the normal archive page is made from.