Is it possible to create categories for tags in taxonomies?

Hi all,

I have a whole lot of articles on my page, sorted with different tags. I’d like to be able to assign those tags to a meta-tag or a category, so that I could range .Site.Taxonomies by tag category.

For example, if we imagine I’m making a website with different musical albums, I’d add a tag for every genre, but there’d also be a meta-tag for categorizing genres, for example “Rock” which could include both “Metal” and “Boogie Woogie” in it.

I don’t mind defining all that in the config.toml-file, if that was an option. Any ideas to how that could be accomplished?

Hugo Taxonomies are not hierarchical, they exist side by side.

A couple of years ago @pointyfar shared a way to achieve complex content filtering in a Hugo project with JS.

See:

1 Like

No way (if I’m correct).
you cann add more genres to one album like

genres = ["rock", "metal" ]

or

use tags genre_group and genre

1 Like

Perhaps you can do something like:

+++
title = "Post 2"
date = 2020-12-21T11:29:44-05:00
draft = false
tags = ["Rock/Metal"]
+++

Here’s a working example:

git clone --single-branch -b hugo-forum-topic-30136 https://github.com/jmooring/hugo-testing hugo-forum-topic-30136
cd hugo-forum-topic-30136
hugo server

Then visit http://localhost:1313/tags/

1 Like

Yes that works. I am already using it. However content published under /rock/metal/ will be of the tags Type and it will exist side by side to content that will be published in the Rock Type under /rock/.

There are no hierarchies. One cannot use a straightforward method to range through .Site.Taxonomies and output for example a tree of Taxonomy links along with their “children”, like:

  • Rock
    • Metal
    • Boogie Woogie
  • Jazz
    • Acid jazz
    • Swing

Currently I am doing the above in a project of mine by manipulating the value of tags = ["Rock/Metal"] to generate the link to the “parent”.

1 Like

Maybe a bit of grouping could work like you want it to? Say,
/config.yaml :

taxonomies:
    tag: "tags" # This is the default anyway

/content/posts/mypost.md (and similar) :

---
tags: ["Rock"]
subtags: ["Metal"] # Not a taxonomy, just a param
---

/layouts/tags/list.html :

<ol>
    {{ range .Pages }}
    <li> {{ .Title }}
        <ol> 
            {{ range .Pages.GroupByParam "subtag" }}
                <li>{{.Key}}
                    <ol>
                        {{ range .Pages }}
                        <li><a href="{{.Permalink}}">😎{{.Title}}</a></li>
                        {{ end }}
                    </ol>
                    </li>
            {{ end }}
        </ol>
    </li>
    {{ end }}
</ol>

Which results in this (public/tags/index.html):

Screenshot from 2020-12-21 16-56-36

Check the full example if you want.

You’ll probably want to take a look at https://gohugo.io/templates/lists/ to see the different methodss available for these kinds of tasks.

1 Like