hugo/docs/content/taxonomies/usage.md
Anthony Fok d397bc4f43 [Docs] Complete the transition from "indexes" to "taxonomies" (almost)
Also mention `.Site.Indexes` → `.Site.Taxonomies` as well as
the upcoming `.Site.Recent` → `.Site.Pages` transitions.
2015-01-29 12:48:14 -07:00

2.2 KiB

date linktitle menu next prev title weight
2014-05-26 Usage
main
parent
taxonomy
/taxonomies/displaying /taxonomies/overview Using Taxonomies 15

Defining taxonomies for a site

Taxonomies must be defined in the site configuration before they can be used throughout the site. You need to provide both the plural and singular labels for each taxonomy.

Here is an example configuration in TOML and YAML that specifies three taxonomies (the default two, plus series).

Notice the format is singular key = "plural value" for TOML, or singular key: "plural value" for YAML:

config.toml excerpt:config.yaml excerpt:
[taxonomies]
  tag = "tags"
  category = "categories"
  series = "series"
taxonomies:
  tag: "tags"
  category: "categories"
  series: "series"

Assigning taxonomy values to content

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

Assigning content to an 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 this content.

taxonomy values are case insensitive

Front Matter Example (in TOML)

+++
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/spf13/hugo"
+++

Front Matter Example (in JSON)

{
    "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/spf13/hugo"
}