Taxonomies
Ways to organize, logically group content. For that Hugo provides:
Tags, Category
Built in taxonomies.
tags = keywords, categories = groups
To implement taxonomies, we use the front matter.
- Add tags, categories taxonomies in a content file like
content/a.md
---
title: "A"
tags: ["tag1", "tag2"]
categories: ["cat1"]
---
Display taxonomies. Then you can display tags and categories of a page when e.g. displaying a card for each page.
Hugo creates pages for taxonomies.
Clicking on a tag name brings you to a list page of this tag e.g. that lists all related posts. The url will look like: tag/tags3
Custom taxonomies
- Use in content .md files
---
title: "A"
tags: ["tag1", "tag2"]
categories: ["cat1"]
moods: ["Happy", "Upbeat"] #added
---
Unlike the default taxonomies (Hugo creates urls for tags, categories), Hugo will not create e.g. moods/happy page.
- Make url pages for custom taxonomies
To remedy this, inhugo.toml
add[taxonomies]
section (note must list the default taxonomies as well):
baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'
theme = 'ga-hugo-theme'
[taxonomies]
tag = "tags" #singular = plural
category = "categories"
mood = "moods"
- Displaying content with the same taxonomy term
(E.g. for a custom taxonomy ’languages’, with value ’english’.)
{{ range .Site.Taxonomies.languages.english }}
// in here we can access the page’s information
{{ .Title }}
{{ .Description }}
{{ end }}
- What other custom taxonomies we could make
-language (for a travel blog. So show all posts where the spoken language in a country is English)
-color (show all works of that color)