Hugo

Only show posts not in a given category

I’d like to know this too. That link does point in the right direction I think, but not enough for me to figure it out yet (I’m new to Hugo and haven’t learned the language and structure enough yet). Has anyone figured this out?

Yes this is possible. Do you have a concrete example of what you’d like to do?

I’m currently using the tranquilpeak theme and want to exclude a couple of categories from the main page. The site is my personal site where I try to keep the blog focused on technology (my profession), but I also want to post about a couple of my hobbies. I’ll link to the hobby posts and allow them to be seen in categories and tags, but I want the main list to stick to my primary categories.

Went ahead and moved this to a new topic and referenced the old one.

So in your theme’s index.html template https://github.com/kakawait/hugo-tranquilpeak-theme/blob/master/layouts/index.html#L14

You’ll wanna add something like this:

{{ range $paginator.Pages }}
  {{ if not (in .Params.categories "foo") }}
    {{ .Render "summary" }}
  {{ end }}
{{ end }}

Where "foo" is the name of the category you want to exclude


If you want to exclude multiple categories you could do:

{{ if and (not (in .Params.categories "foo1")) (not (in .Params.categories "foo2")) }}
2 Likes

Thank you! I’ll try this later tonight and report back.

Update: That worked great! Really appreciate the help. My attempts were still not close. Lol.

Glad to help :+1: