Category in a hugo template

how to display the categories of the site and the number of articles of these categories in the home page .

{{ range $term, $weightedPages := site.Taxonomies.categories }}
  {{ $term }} {{ $weightedPages.Len }}
{{ end }}
1 Like

Thank you for your reply
however I want to display some categories only not all categories?

{{ $termsOfInterest := slice "a" "b" }}
{{ range $term, $weightedPages := site.Taxonomies.categories }}
  {{ if in $termsOfInterest $term }}
    {{ $term }} {{ $weightedPages.Len }}
  {{ end }}
{{ end }}

There are no links from these categories !
Any idea ?

First you asked how to display the categories.
Then you asked how to display only some categories.
Now you’re asking for something else.

How about a definitive requirement, or is the last ask?

1 Like

Just a remark:
displaying categories without the link that leads to the articles of these categories is not my question that’s all

<ul>
  {{ $termsOfInterest := slice "a" "b" }}
  {{ range $term, $weightedPages := site.Taxonomies.categories }}
    {{ if in $termsOfInterest $term }}
      <li><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ $weightedPages.Len }})</li>
    {{ end }}
  {{ end }}
</ul>
2 Likes

It works, thank you.

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