github.com/jbramsden/hugo@v0.47.1/docs/content/en/content-management/taxonomies.md (about)

     1  ---
     2  title: Taxonomies
     3  linktitle:
     4  description: Hugo includes support for user-defined taxonomies to help you  demonstrate logical relationships between content for the end users of your website.
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-02-01
     8  keywords: [taxonomies,metadata,front matter,terms]
     9  categories: [content management]
    10  menu:
    11    docs:
    12      parent: "content-management"
    13      weight: 80
    14  weight: 80	#rem
    15  draft: false
    16  aliases: [/taxonomies/overview/,/taxonomies/usage/,/indexes/overview/,/doc/indexes/,/extras/indexes]
    17  toc: true
    18  ---
    19  
    20  ## What is a Taxonomy?
    21  
    22  Hugo includes support for user-defined groupings of content called **taxonomies**. Taxonomies are classifications of logical relationships between content.
    23  
    24  ### Definitions
    25  
    26  Taxonomy
    27  : a categorization that can be used to classify content
    28  
    29  Term
    30  : a key within the taxonomy
    31  
    32  Value
    33  : a piece of content assigned to a term
    34  
    35  {{< youtube pCPCQgqC8RA >}}
    36  
    37  ## Example Taxonomy: Movie Website
    38  
    39  Let's assume you are making a website about movies. You may want to include the following taxonomies:
    40  
    41  * Actors
    42  * Directors
    43  * Studios
    44  * Genre
    45  * Year
    46  * Awards
    47  
    48  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.
    49  
    50  ### Movie Taxonomy Organization
    51  
    52  To continue with the example of a movie site, the following demonstrates content relationships from the perspective of the taxonomy:
    53  
    54  ```
    55  Actor                    <- Taxonomy
    56      Bruce Willis         <- Term
    57          The Sixth Sense  <- Value
    58          Unbreakable      <- Value
    59          Moonrise Kingdom <- Value
    60      Samuel L. Jackson    <- Term
    61          Unbreakable      <- Value
    62          The Avengers     <- Value
    63          xXx              <- Value
    64  ```
    65  
    66  From the perspective of the content, the relationships would appear differently, although the data and labels used are the same:
    67  
    68  ```
    69  Unbreakable                 <- Value
    70      Actors                  <- Taxonomy
    71          Bruce Willis        <- Term
    72          Samuel L. Jackson   <- Term
    73      Director                <- Taxonomy
    74          M. Night Shyamalan  <- Term
    75      ...
    76  Moonrise Kingdom            <- Value
    77      Actors                  <- Taxonomy
    78          Bruce Willis        <- Term
    79          Bill Murray         <- Term
    80      Director                <- Taxonomy
    81          Wes Anderson        <- Term
    82      ...
    83  ```
    84  
    85  ## Hugo Taxonomy Defaults {#default-taxonomies}
    86  
    87  Hugo natively supports taxonomies.
    88  
    89  Without adding a single line to your [site config][config] file, Hugo will automatically create taxonomies for `tags` and `categories`. That would be same as manually [configuring your taxonomies](#configuring-taxonomies) as below:
    90  
    91  {{< code-toggle copy="false" >}}
    92  [taxonomies]
    93    tag = "tags"
    94    category = "categories"
    95  {{</ code-toggle >}}
    96  
    97  If you do not want Hugo to create any taxonomies, set `disableKinds` in your [site config][config] to the following:
    98  
    99  {{< code-toggle copy="false" >}}
   100  disableKinds = ["taxonomy","taxonomyTerm"]
   101  {{</ code-toggle >}}
   102  
   103  ### Default Destinations
   104  
   105  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:
   106  
   107  * A single page at `example.com/categories/` that lists all the [terms within the taxonomy][]
   108  * [Individual taxonomy list pages][taxonomy templates] (e.g., `/categories/development/`) for each of the terms that shows a listing of all pages marked as part of that taxonomy within any content file's [front matter][]
   109  
   110  ## Configure Taxonomies {#configuring-taxonomies}
   111  
   112  Custom taxonomies other than the [defaults](#default-taxonomies) must be defined in your [site config][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.
   113  
   114  ### Example: Adding a custom taxonomy named "series"
   115  
   116  {{% note %}}
   117  While adding custom taxonomies, you need to put in the default taxonomies too, _if you want to keep them_.
   118  {{% /note %}}
   119  
   120  {{< code-toggle copy="false" >}}
   121  [taxonomies]
   122    tag = "tags"
   123    category = "categories"
   124    series = "series"
   125  {{</ code-toggle >}}
   126  
   127  ### Example: Removing default taxonomies
   128  
   129  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][config].
   130  
   131  {{< code-toggle copy="false" >}}
   132  [taxonomies]
   133    tag = "tags"
   134  {{</ code-toggle >}}
   135  
   136  If you want to disable all taxonomies altogether, see the use of `disableKinds` in [Hugo Taxonomy Defaults](#default-taxonomies).
   137  
   138  ### Preserve Taxonomy Values
   139  
   140  By default, taxonomy names are normalized.
   141  
   142  Therefore, if you want to have a taxonomy term with special characters such as `GĂ©rard Depardieu` instead of `Gerard Depardieu`, set the value for `preserveTaxonomyNames` to `true` in your [site config][config]. Hugo will then preserve special characters in taxonomy values but will still title-ize the values for titles and normalize them in URLs.
   143  
   144  Note that if you use `preserveTaxonomyNames` and intend to manually construct URLs to the archive pages, you will need to pass the taxonomy values through the [`urlize` template function][].
   145  
   146  {{% note %}}
   147  You can add content and front matter to your taxonomy list and taxonomy terms pages. See [Content Organization](/content-management/organization/) for more information on how to add an `_index.md` for this purpose.
   148  
   149  Much like regular pages, taxonomy list [permalinks](/content-management/urls/) are configurable, but taxonomy term page permalinks are not.
   150  {{% /note %}}
   151  
   152  ## Add Taxonomies to Content
   153  
   154  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][].
   155  
   156  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.
   157  
   158  {{% note %}}
   159  If you would like the ability to quickly generate content files with preconfigured taxonomies or terms, read the docs on [Hugo archetypes](/content-management/archetypes/).
   160  {{% /note %}}
   161  
   162  ### Example: Front Matter with Taxonomies
   163  
   164  {{< code-toggle copy="false">}}
   165  title = "Hugo: A fast and flexible static site generator"
   166  tags = [ "Development", "Go", "fast", "Blogging" ]
   167  categories = [ "Development" ]
   168  series = [ "Go Web Dev" ]
   169  slug = "hugo"
   170  project_url = "https://github.com/gohugoio/hugo"
   171  {{</ code-toggle >}}
   172  
   173  ## Order Taxonomies
   174  
   175  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`.
   176  
   177  The following TOML and YAML examples 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.
   178  
   179  ### Example: Taxonomic `weight`
   180  
   181  {{< code-toggle copy="false" >}}
   182  title = "foo"
   183  tags = [ "a", "b", "c" ]
   184  tags_weight = 22
   185  categories = ["d"]
   186  categories_weight = 44
   187  {{</ code-toggle >}}
   188  
   189  By using taxonomic weight, the same piece of content can appear in different positions in different taxonomies.
   190  
   191  {{% note "Limits to Ordering Taxonomies" %}}
   192  Currently taxonomies only support the [default `weight => date` ordering of list content](/templates/lists/#default-weight-date). For more information, see the documentation on [taxonomy templates](/templates/taxonomy-templates/).
   193  {{% /note %}}
   194  
   195  ## Add custom metadata to a Taxonomy Term
   196  
   197  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 it's 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:
   198  
   199  {{< code file="/content/actors/bruce-willis/_index.md" >}}
   200    ---
   201    title: "Bruce Willis"
   202    wikipedia: "https://en.wikipedia.org/wiki/Bruce_Willis"
   203    ---
   204  {{< /code >}}
   205  
   206  You can later use your custom metadata as shown in the [Taxonomy Terms Templates documentation](/templates/taxonomy-templates/#displaying-custom-metadata-in-taxonomy-terms-templates).
   207  
   208  [`urlize` template function]: /functions/urlize/
   209  [content section]: /content-management/sections/
   210  [content type]: /content-management/types/
   211  [documentation on archetypes]: /content-management/archetypes/
   212  [front matter]: /content-management/front-matter/
   213  [taxonomy list templates]: /templates/taxonomy-templates/#taxonomy-page-templates
   214  [taxonomy templates]: /templates/taxonomy-templates/
   215  [terms within the taxonomy]: /templates/taxonomy-templates/#taxonomy-terms-templates "See how to order terms associated with a taxonomy"
   216  [config]: /getting-started/configuration/