Adding list of tags to my homepage

Hi, I have created hugo site based on this theme GitHub - nodejh/hugo-theme-mini: A fast, minimalist and responsive hugo theme for bloggers.
This theme has page with all generated tags ( http://localhost:1313/tags/ ) , however i want to place all my tags on my home page at the top before the articles, how can i do that?

https://gohugo.io/templates/taxonomy-templates/#example-list-all-site-tags

1 Like

Thanks for the link, on that page I found that in order to generate tags list I need to use this code:

<ul>
    {{ range .Site.Taxonomies.tags }}
            <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
    {{ end }}
</ul>

my website homepage html file looks like this:

{{ define "main" }} {{ partial "profile.html" . }}
{{ $pages := .Site.RegularPages }} {{ $paginator := .Paginate ($pages) }} {{ range $paginator.Pages }} {{ $title := .Title }} {{ $summary := .Summary }}


{{ $title }}
{{ i18n "publishDate" . }} 
{{ if ne .Site.Params.hiddenPostSummaryInHomePage true }}
{{ $summary | plainify | htmlUnescape }}
{{ end }} 
{{ end }} {{ if or ($paginator.HasPrev) ($paginator.HasNext) }}
{{ if $paginator.HasPrev }} ← {{ with .Site.Params.newerPosts }}{{ . }}{{ else }}{{ i18n "postsNewer" }}{{ end }} {{ end }} {{ if $paginator.HasNext }} {{ with .Site.Params.olderPosts }}{{ . }}{{ else }}{{ i18n "postsOlder" }}{{ end }} → {{ end }} 
{{ end }} 
{{ end }} 

Can i just paste tag’s list code into my homepage html file ?

Yes, provided that it appears after {{ define "main" }}.

And I assume your “homepage html file” is a template (in the layouts directory) and not content.

yes, my homepage html file is located in /layouts in theme’s folder

I have pasted code after {{ define "main" }} however now my homepage is a blank white page without content (there was content before i pasted the code)

{{ define "main" }} 
<ul>
    {{ range .Site.Taxonomies.tags }}
            <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
    {{ end }}
</ul>
{{ partial "profile.html" . }}
{{ $pages := .Site.RegularPages }} {{ $paginator := .Paginate ($pages) }} {{ range $paginator.Pages }} {{ $title := .Title }} {{ $summary := .Summary }}
{{ $title }}
{{ i18n "publishDate" . }} 
{{ if ne .Site.Params.hiddenPostSummaryInHomePage true }}
{{ $summary | plainify | htmlUnescape }}
{{ end }} 
{{ end }} {{ if or ($paginator.HasPrev) ($paginator.HasNext) }}
{{ if $paginator.HasPrev }} ← {{ with .Site.Params.newerPosts }}{{ . }}{{ else }}{{ i18n "postsNewer" }}{{ end }} {{ end }} {{ if $paginator.HasNext }} {{ with .Site.Params.olderPosts }}{{ . }}{{ else }}{{ i18n "postsOlder" }}{{ end }} → {{ end }} 
{{ end }} 
{{ end }} 

Please show the directory structure of your layouts directory.

OK, we’re going need to look at your repository.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Works fine for me like this:

By the way, instead of modifying files in the themes directory, copy the files you want to modify to the layouts directory in the root of your project. That way you can reinstall or update the theme without losing your work. Example:

project/
└── layouts/
    ├── _default/
    ├── partials/
    └── shortcodes/

1 Like

I found that the problem with white blank page is not caused by pasting this code, for some reasons if I make any change in index.html the homepage becomes blank white, even if I undo changes in index.html the screen is still white. Only when I replace index.html with old untouched version of index.html the content appears on the homepage again.

I obviously didn’t have that problem. Not sure what you’re doing wrong.

I found that problem with blank page was caused by using mac text editor instead of any other editor with html support, now everything is working including tags on the homepage, thanks for the help!!!

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