HUGO

List of categories from a specific section

I’ve been trying to create a section specific list of categories.
I have the following code that produces links to all categories from site content.

{{ range ($.Site.GetPage "taxonomyTerm" "categories").Pages }}
     <li><a href="{{ .Permalink }}">{{ .Name }}</a></li>
{{ end }}

How can I display categories only from the current section? For example, on the list.html page of the blog section, I would like to display a list of only the categories that are added to content items in the blog section.

I did it like

{{ $t := where .Site.Taxonomies.categories.ByCount ".Page.Section" "blog" }}
{{ range $t }}
  <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a></li>
{{ end }}

Replace the section blog to any you want to.

This topic was automatically closed after 2 days. New replies are no longer allowed.