Light Dark

Hugo Ordered Taxonomies


While it seems to be possible to order taxonomies in a list layout using the built-in weights system, I found it to be overkill, as it requires creating a bunch of directories and _index.mds . Instead, you can simply hardcode a list of taxonomy values and iterate through them. It, of course, requires from you to maintain an explicit list of what to display, but many times that’s what you want anyway.

{{ $categories := (slice "Life" "Tech" "Snippets")}}

{{ range $category := $categories }}

  <h1>{{ $category | humanize }}</h1>

  {{ range where $.Pages "Params.categories" "intersect" (slice $category) }}

      <a href="{{.Permalink}}">{{.Title}}</a>
      <span>{{.Date.Format "January 2006"}}</span>

  {{ end }}

{{ end }}