hugo/content/en/content-management/taxonomies.md
Bjørn Erik Pedersen 00c4484c70 Squashed 'docs/' changes from 392668f4f..32cb8785e
32cb8785e Fix page weights in content management section (#1896)
11977b96f Make relURL and related functions consistent (#1895)
f12180207 Clarify github deployment (#1894)
958877789 Remove remaining references to Highlight.js (#1893)
fc487d263 Minor edit to taxonomy page
3b6a224b2 Update theme
b28553b62 Change "flavor" to "edition" when referring to builds (#1892)
660e7581c Replaced sudo in OpenBSD with doas (#1891)
e3fcdea10 fix a few minor grammatical issues on Firebase docs (#1889)
e4c8b30eb update Static Web Apps docs (#1890)
da2197c9e Update hosting-on-firebase.md (#1347)
5f2a0c271 Adding deployment guide for Azure Static Web Apps (#1456)
5aaf570cd add Azure Static Web App config to 404 template
35fc54362 add Azure Static Web App config to 404 template
d48f67ba1 Update 01-flavors.md
11debae8d Cleaned Use of ref and relref section, added refs of index.md and _in… (#1744)
b77604078 docs: Add link to menu entry variables (#1827)
0fa8a6bf0 Misc copy edits (#1887)
c27b545ac Improve explanation of safeHTMLAttr's function (#1503)
b04a4b32e Make CLI command summaries meaningful (#1886)
dbf00a81f Fix a typo in diagrams documentation (#1885)
11f884327 docs: Clarify how to remove draft/future/expired content (#1831)
6dc9e9860 Improve complement function (#1884)
56448a51a Remove erroneous sourcemap desc (#1883)
a0d0d2829 Merge branch 'divinerites-patch-1'
10f20cb5e Add a plausible-hugo theme component
9f1413eb5 Minor edits to showcase example
7d78420db fix broken link to Isso Comments
925cb291f Make directory tree consistent with other examples
300fff092 Add link to security policy from getenv.md (#1746)
7b4c517a6 Fix docs menu weights
ce35775e0 Update faq.md (#1763)
f3fb791a4 Remove dated new-in flags (#1879)
b6c634629 Remove deprecated templating langs (#1880)
1b25ca34f Update the findRE and replaceRE functions (#1881)
28757ec73 Add Alora Labs website to showcase (#1494)
e3c4bc4e7 Remove unimplemented "ugly" property
86afd84ff Update editors.md (#1878)
44c093911 Add urlquery function docs (#1633)
16a8c3548 Update links to installation page (#1876)
9e357f078 Add missing sections to BSD installation page (#1875)
1b1291634 Promote "Installation" to a section
9dd51235b Add detail to description of .Plain page variable (#1870)
d333d0287 Minor markdown linting fix and URL updates (#1873)
d57c8aa50 Remove extraneous apostrophe (#1871)
8c25cfc5c Update index.md
09fea41e0 Add lang to fenced code block
35b904798 Add small documentation about .Site.Social.twitter variable (#1854)
672042f89 Consolidate site configuration
dfd4dd873 Add help.ampio.com showcase. (#1863)
e8d0e7bdf Include link to internal templates code (#1794)
7db6f0c01 Add example to split function (#1867)
be87dba80 Clarify split function docs (#1792)
a079193f1 Fix typo on data templates page
b234c70ee Fix data templates page (#1855)
074232b45 Update front-matter.md (#1856)
711c8fa80 Added missing default value (#1862)
034762882 Fixed some grammar issues and typos (#1865)
764574a4d Fix spelling error
2698f2d44 update URLs to prevent redirects (#1864)
68f05fdc8 Fenced code blocks should have a language specified (#1861)
24393315b GitHub Workflows security hardening (#1859)
3eeee13bf Markdown formatting: Add Fenced code block languages (#1858)
e152cdf1f netlify: Hugo 0.105.0
4c7fc9f7e Merge branch 'tempv0.105.0'
d16710afc Change anchor reference to use relref function calls (#1853)
f52af8e4a tpl/encoding: Add noHTMLEscape option to jsonify
eca0046c4 Update hosting-on-keycdn docs (#1852)
ffbe17a48 Add note for rsync deploy command (#1415)
c482133f1 docs: Update quick start to clarify the need of extended version (#1828)
1e3b33804 use correct URL for Google Search console verification (#1851)
dac034f63 Markdown and formatting fixes (#1850)
43f177e3c Fix LiveReload in quick-start (#1739)
f78deaa5f Add link for ''Hugo Shortcode Syntax Highlighting' VS Code extension (#1765)
08087ecd7 Remove some hidden pages (#1848)
b6cb5ae48 Markdown linting fixes (#1846)
527ec5941 Update hugo.md (#1742)
83e8f2168 Clarify that a shortcode with .Inner must be closed (#1785)
4193f4445 Add Super Linter GitHub Action (#1845)
fd91bfe1a Formatting and grammar fixes (#1844)
ab5a49c49 Create codeql-analysis GitHub Action (#1812)
63b3e082e Add tutorial on using fusejs to search examples (#1756)
54c253ab0 Note that Google Universal Analytics are deprecated (#1770)
385fa77c6 Update articles.toml (#1840)
5e336bd26 Replace awkward wording (ESL?) (#1842)
2446ad349 Added Introduction to Hugo tutorial/video series (#1736)
7b21b2e76 Don't use self-closing generator tag
ef73712ff Image processing. available methods: add method 'Colors' (#1837)
018f83bbe [comment platform] - add new alternative (#1751)
5636c208b Grammar and spelling fixes (#1836)
3f2e26f77 Change link of repojacking vulnerable link - JekyllToHugo (#1834)
301379fc3 fix: use shorter image URL to make it easier to read (#1835)
de5fa7b30 Update search.md to include Pagefind (#1826)
e9d72bcda Breadcrumb example: add basic accessibility (#1832)
6cffff87a netlify: Hugo 0.104.3
892360f61 Update output-formats.md
09a7a46ae Remove my defunct and little used migrator (#1824)
347434cca netlify: Hugo 0.104.2
f8c721162 Update postcss.md
c2baf7155 netlify: Hugo 0.104.1
05d1192cd Update diagrams.md (#1823)
3c43a8bbe netlify: Hugo 0.104.0
57973b334 Merge branch 'tempv0.104.0'
da775a36d docs: Regen docs helper
ae48b5901 docs: Regenerate CLI docs
af4a823b1 resources/images: Add $image.Colors
8e3f9ca64 Remove outdated IE conditional comments example (#1821)
d1a84701b fix typo in template introduction (#1820)
c0c7339e0 Update internal.md
17aefc515 Remove the recommendation about where to put the GA tempalte
263297236 Adjust GA template instructions
1cc265d99 Update the GA template usage section
e11968338 config/security: Allow proxy variables in subcommands
9218ab993 netlify: Hugo 0.103.1
0b0e890d1 Update markdownify and RenderString documentation (#1818)
50f5d4776 Fix internal link (#1817)
6beb443c5 netlify: Hugo 0.103.0
14b5af248 Merge branch 'tempv0.103.0'
548e7aa62 server: Add 404 support
3a20aa0ba Update theme

git-subtree-dir: docs
git-subtree-split: 32cb8785ea74d5b82f2e2bea79d059cab497902a
2022-11-17 16:14:29 +01:00

8.5 KiB

title linkTitle description keywords categories menu toc weight aliases
Taxonomies Taxonomies Hugo includes support for user-defined taxonomies.
taxonomies
metadata
front matter
terms
content management
docs
parent weight
content-management 150
true 150
/taxonomies/overview/
/taxonomies/usage/
/indexes/overview/
/doc/indexes/
/extras/indexes

What is a Taxonomy?

Hugo includes support for user-defined groupings of content called taxonomies. Taxonomies are classifications of logical relationships between content.

Definitions

Taxonomy
a categorization that can be used to classify content
Term
a key within the taxonomy
Value
a piece of content assigned to a term

Example Taxonomy: Movie Website

Let's assume you are making a website about movies. You may want to include the following taxonomies:

  • Actors
  • Directors
  • Studios
  • Genre
  • Year
  • Awards

Then, in each of the movies, you would specify terms for each of these taxonomies (i.e., in the front matter of each of your movie content files). From these terms, Hugo would automatically create pages for each Actor, Director, Studio, Genre, Year, and Award, with each listing all of the Movies that matched that specific Actor, Director, Studio, Genre, Year, and Award.

Movie Taxonomy Organization

To continue with the example of a movie site, the following demonstrates content relationships from the perspective of the taxonomy:

Actor                    <- Taxonomy
    Bruce Willis         <- Term
        The Sixth Sense  <- Value
        Unbreakable      <- Value
        Moonrise Kingdom <- Value
    Samuel L. Jackson    <- Term
        Unbreakable      <- Value
        The Avengers     <- Value
        xXx              <- Value

From the perspective of the content, the relationships would appear differently, although the data and labels used are the same:

Unbreakable                 <- Value
    Actors                  <- Taxonomy
        Bruce Willis        <- Term
        Samuel L. Jackson   <- Term
    Director                <- Taxonomy
        M. Night Shyamalan  <- Term
    ...
Moonrise Kingdom            <- Value
    Actors                  <- Taxonomy
        Bruce Willis        <- Term
        Bill Murray         <- Term
    Director                <- Taxonomy
        Wes Anderson        <- Term
    ...

Hugo Taxonomy Defaults

Hugo natively supports taxonomies.

Without adding a single line to your site config file, Hugo will automatically create taxonomies for tags and categories. That would be the same as manually configuring your taxonomies as below:

{{< code-toggle copy="false" >}} [taxonomies] tag = "tags" category = "categories" {{</ code-toggle >}}

If you do not want Hugo to create any taxonomies, set disableKinds in your site config to the following:

{{< code-toggle copy="false" >}} disableKinds = ["taxonomy","term"] {{</ code-toggle >}}

{{% page-kinds %}}

Default Destinations

When taxonomies are used---and taxonomy templates are provided---Hugo will automatically create both a page listing all the taxonomy's terms and individual pages with lists of content associated with each term. For example, a categories taxonomy declared in your configuration and used in your content front matter will create the following pages:

Configure Taxonomies

Custom taxonomies other than the [defaults]({{< relref "taxonomies.md#default-taxonomies" >}}) must be defined in your site config before they can be used throughout the site. You need to provide both the plural and singular labels for each taxonomy. For example, singular key = "plural value" for TOML and singular key: "plural value" for YAML.

Example: Adding a custom taxonomy named "series"

{{% note %}} While adding custom taxonomies, you need to put in the default taxonomies too, if you want to keep them. {{% /note %}}

{{< code-toggle copy="false" >}} [taxonomies] tag = "tags" category = "categories" series = "series" {{</ code-toggle >}}

Example: Removing default taxonomies

If you want to have just the default tags taxonomy, and remove the categories taxonomy for your site, you can do so by modifying the taxonomies value in your site config.

{{< code-toggle copy="false" >}} [taxonomies] tag = "tags" {{</ code-toggle >}}

If you want to disable all taxonomies altogether, see the use of disableKinds in [Hugo Taxonomy Defaults]({{< relref "taxonomies.md#default-taxonomies" >}}).

{{% note %}} You can add content and front matter to your taxonomy list and taxonomy terms pages. See Content Organization for more information on how to add an _index.md for this purpose.

Much like regular pages, taxonomy list permalinks are configurable, but taxonomy term page permalinks are not. {{% /note %}}

{{% warning %}} The configuration option preserveTaxonomyNames was removed in Hugo 0.55.

You can now use .Page.Title on the relevant taxonomy node to get the original value. {{% /warning %}}

Add Taxonomies to Content

Once a taxonomy is defined at the site level, any piece of content can be assigned to it, regardless of content type or content section.

Assigning content to a taxonomy is done in the front matter. Simply create a variable with the plural name of the taxonomy and assign all terms you want to apply to the instance of the content type.

{{% note %}} If you would like the ability to quickly generate content files with preconfigured taxonomies or terms, read the docs on Hugo archetypes. {{% /note %}}

Example: Front Matter with Taxonomies

{{< code-toggle copy="false">}} title = "Hugo: A fast and flexible static site generator" tags = [ "Development", "Go", "fast", "Blogging" ] categories = [ "Development" ] series = [ "Go Web Dev" ] slug = "hugo" project_url = "https://github.com/gohugoio/hugo" {{</ code-toggle >}}

Order Taxonomies

A content file can assign weight for each of its associate taxonomies. Taxonomic weight can be used for sorting or ordering content in taxonomy list templates and is declared in a content file's front matter. The convention for declaring taxonomic weight is taxonomyname_weight.

The following show a piece of content that has a weight of 22, which can be used for ordering purposes when rendering the pages assigned to the "a", "b" and "c" values of the tags taxonomy. It has also been assigned the weight of 44 when rendering the "d" category page.

Example: Taxonomic weight

{{< code-toggle copy="false" >}} title = "foo" tags = [ "a", "b", "c" ] tags_weight = 22 categories = ["d"] categories_weight = 44 {{</ code-toggle >}}

By using taxonomic weight, the same piece of content can appear in different positions in different taxonomies.

{{% note "Limits to Ordering Taxonomies" %}} Currently taxonomies only support the default weight => date ordering of list content. For more information, see the documentation on taxonomy templates. {{% /note %}}

Add custom metadata to a Taxonomy or Term

If you need to add custom metadata to your taxonomy terms, you will need to create a page for that term at /content/<TAXONOMY>/<TERM>/_index.md and add your metadata in its front matter. Continuing with our 'Actors' example, let's say you want to add a Wikipedia page link to each actor. Your terms pages would be something like this:

{{< code file="/content/actors/bruce-willis/_index.md" >}}

title: "Bruce Willis" wikipedia: "https://en.wikipedia.org/wiki/Bruce_Willis"

{{< /code >}}