Tags and categories list in the post

Hi,

I started using Hugo and I have a small problem with tags and categories.

In the Hugo configuration file I added:

[taxonomies]
category = ‘categories’
tag = ‘tags’

In the test post (test.md)I added an entry regarding tags:

+++
title = ‘Test’
date = 2025-02-11T15:07:26Z
draft = false
tags = [“test”, “blog”]
+++

When I go to -mydomain.co.uk/tags/ or -mydomain.co.uk/categories/ I see a list of tags and categories.

What do I need to do to see added tags and categories at the top of the post under the post title?

I am using theme: Hugo blog awesome

unfortunately you are on your own. The theme has no code inside to render terms or categories beyond the standard /tags and /categories listings.

you’ll have to adjust the templates of the theme.

here’s an example for the tags from theme generated by hugo new theme

  • place the partial from _layouts/partials/terms.html in your layouts/partials/ folder

    here's the content:
    {{- /*
    For a given taxonomy, renders a list of terms assigned to the page.
    
    @context {page} page The current page.
    @context {string} taxonomy The taxonomy.
    
    @example: {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
    */}}
    
    {{- $page := .page }}
    {{- $taxonomy := .taxonomy }}
    
    {{- with $page.GetTerms $taxonomy }}
    {{- $label := (index . 0).Parent.LinkTitle }}
    <div>
        <div>{{ $label }}:</div>
        <ul>
        {{- range . }}
            <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
        {{- end }}
        </ul>
    </div>
    {{- end }}
    
  • copy the template for a single page from the hba theme to your own layouts folder
    source: themes\hugo-blog-awesome\layouts\_default\single.html
    target: layouts\_default\single.html

  • call the parial inside to add the terms to the page fe direct before the header closing tag

    {{ define "main" }}
       ...
             <header class="header">
                ...
                 {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
             </header>
       ...
    {{ end }}
    

I don’t have a _layouts/partials/ folder in my main hugo folder. I only have layouts/ but it’s empty

UPDATE:
So I created a file: layouts/partials/terms.html

I added what you gave me.

Then I copied
source: themes\hugo-blog-awesome\layouts_default\single.html
target: layouts_default\single.html

and added

{{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}  

right above

</header>

Unfortunately when I go to posts I still don’t see a list of tags or categories.
I know I must have done something wrong

at least you have a type hear missing a path separator :wink:

That was tested with a fresh cloned of hba and it worked fine

kinda looks like - if you cannot find it, please share your repo

Silly me!
I made a mistake and copied it to the _defaults folder
It should be _default
Thank you very much @irkode for your help!

Two more thing, maybe you know if it is possible.

As you can see in the screenshot, the tags are displayed one after another.

Is it possible to display them in one line?
For example: tag1, tag2, tag3

Second issue.
Why doesn’t the Table of contents caption display for me?

Zero: we usually follow the one issue one topic philosophy especially if the topics changes

First: sure it is

it’s done by customizing the partial from my first answer. That one creates an unordered list to display the tags.

just change it to create a comma separated list :wink:

Tags with comma
{{- /*
For a given taxonomy, renders a list of terms assigned to the page.

@context {page} page The current page.
@context {string} taxonomy The taxonomy.

@example: {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
*/}}

{{- $page := .page }}
{{- $taxonomy := .taxonomy }}

{{- with $page.GetTerms $taxonomy }}
{{- $label := (index . 0).Parent.LinkTitle }}
<div>{{ $label }}:
    {{ range $k, $v := . -}}
        {{- if $k }}, {{ end -}}<a href="{{ $v.RelPermalink }}">{{ $v.LinkTitle }}</a>
    {{- end -}}
</div>
{{- end }}

Second: the theme uses i18n to translate static texts.

without having access to your repo It’s just guessing

  • your posts are in an unsupported language
  • you have a misconfigured language config
  • broke something in the translation config or layouts.

share your repo if you cannot find it.

@irkode you are the BEST!

The tags are now displayed the way I want them to be.
You’ve guided me to restore the Tables of contents label.
I had Hugo configured incorrectly.
Now everything is the way I want it!
Thank you very much!

1 Like

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