[solved] Can I limit taxonomy pages within a directory? (directory aka section)

I am making two directories (say blog, products). I want taxonomies like categories etc per blog and product instead of at the root.

Is there a way to achieve this with modifying the configuration with a single hugo application?

I guess that only works if you introduce separate taxonomies for the desired groups like blog & products

like:

  • blog_tag
  • product_tag

Found the solution. Since these directories are called section. I got it working through

Part of the solution was used from some other answer in the same forum.

With this, I could make a widget kind of which takes categories from the site and limits them to blog section of which it limits to 5 entries.

{{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
  {{ if eq "categories" $taxonomyname }}
    {{ range $key, $value := $taxonomy }}
    {{ if ge (where $value.Pages "Section" "blog") 1 }}
    <div class="col-md-3 col-sm-6 col-xs-12">
      <h4 class="text-center">{{ $key }}</h4>
      <ol>
      {{range first 5 (where $value.Pages "Section" "blog") }}
        <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
      {{ end }}
      </ol>
    </div>
    {{ end }}
    {{ end }}
  {{ end }}
{{ end }}

2 Likes

Cool, I save this in my code snippets!

Sure.

All code should be under the same license as hugo itself since its their forum.