Recreating categories and tags | template lookup?

So, I’m trying to get my site built in Hugo – repo here – after using WordPress for years. I’ve got most of the basics running, but categories and tags are incredibly confusing – I’ve read all the docs I can find.

I’ve got categories in all the front matter for each post (in /content/post), and I’ve got a template for each post (/layouts/post/single.html) to show the categories :

  {{ if isset .Params "categories" }}
            <div class="level-item">
                <p class="heading">In:  {{ range .Params.categories }}
                    <a href="{{ "/categories/" | relLangURL }}{{ . | urlize }}">{{ . }}</a>
                {{ end }}</p>
            </div>
            {{ end }}

That all seems to work OK. It generates a page at /categories/term/, but that’s blank.

Where do I put a template to make this list the content associated with a category’s term? I’ve got a directory called ‘categories’ in /layouts… and that doesn’t seem to be working.

Here’s my layout structure:

themes/zb/layouts/
├── 404.html
├── _default
│ ├── baseof.html
│ ├── list.html
│ ├── section.html
│ └── single.html
├── categories
│ └── terms.html
├── index.html
├── partials
│ ├── about.html
│ ├── blog-home.html
│ ├── footer.html
│ ├── head.html
│ ├── hero-image.html
│ ├── hero-node.html
│ ├── hero-video.html
│ ├── nav.html
│ ├── post-hero.html
│ ├── post-list.html
│ ├── three-tiles.html
│ ├── top-section.html
│ ├── video.html
│ └── wood-section.html
├── post
│ ├── post.html
│ └── single.html
└── section-old
└── post.html

I have to agree, the documentation on Tags and Categories is woefully inadequate. The video from GA makes it appear like magic. If I could, I’d write up a step by step, but after a week tearing apart templates that succeed, I still have no idea how to implement it on the Creative template that does not support it.

It seems that what is needed is a description of 3 main things.

  1. How to add tags and categories to content front matter (this is covered in the GA video)
  2. How to create a Tag or Category “roll-up” page (I guess it’s a List page, but I don’t know.
  3. How to create a \tag\mytag list page that lists only the content with “mytag”. (This has been the hardest part for me.)
  4. How to change the URL of the permalink from site\tag to site\blog\tag or something else.

I am sorry that this is not the help you are looking for. But now you know you are not alone.

1 Like

Everything is documented; may be you are missing the key word taxonomies.

How to add tags and categories to content front matter

I won’t list links to all of your points, but everything is documented. I’d suggest that you read the entire Taxonomies | Hugo section and then report back on stuff that was not clear.

I’d also like to point you to my minimal theme hugo-bare-min-theme that might help you figure out the template layout structure… (yes, that “roll-up” page is a “list” page). Going through Page Kinds in the documentation will also help.

THANK YOU for the reply.

What is not clear are points 2, 3, and 4 in my post. For example. Do I create a new layout page that is supposed to list all of the Post that are tagged with a specific tag? Where does that go? How does that work?

My current hugo build is creating the tags folder and the specific tag sub folders, but there are only XML files in the folder, no HTML.

I have no idea why.

Since so many themes are missing this functionality I assume it is not as easy as it looks, or nobody uses these additional features.

Do I create a new layout page that is supposed to list all of the Post that are tagged with a specific tag?

You can create a taxo specific layout, but in most cases, the same list.html works for almost everything. See how I reuse that one layout for various Page Kinds in my bare-min theme.

Where does that go? How does that work?

If in doubt, put stuff in your layouts/_default/ dir.

See Lookup Order – Taxonomy List pages for more details.

My current hugo build is creating the tags folder and the specific tag sub folders, but there are only XML files in the folder, no HTML.

Difficult to tell… I’d suggest that you start with the exampleSite in one of the existing themes… you probably messed with outputs in your site’s config.toml?

Since so many themes are missing this functionality I assume it is not as easy as it looks, or nobody uses these additional features.

I think almost all themes support taxonomies… it’s very easy and common.


Once you understand 100% of the bare-min theme, these questions will be answered :slight_smile:.

Also — hugo-bare-min-theme Demo | Source

Awesome! Thanks, I’ll take the afternoon to do as you say and start with the bare-min theme. The only answer I do have for you from above is I don’t have a reference to outputs in my config.toml file.

I really appreciate your time for the response. This is the only thing keeping me from deploying my site.

Thank You.

Wow, there is a lot in that “bare min” template! :slight_smile: But THANK YOU. I got the pages working and rendering, now I just need to apply my styling. Then I can have a look at your Twitter Card and Short Code examples!

Thanks again @kaushalmodi