Debian Codegraph @

docs/content/en/content-management/taxonomies.md

raw
1 ---
2 title: Taxonomies
3 description: Hugo includes support for user-defined taxonomies.
4 categories: []
5 keywords: []
6 aliases: [/taxonomies/overview/,/taxonomies/usage/,/indexes/overview/,/doc/indexes/,/extras/indexes]
7 ---
8
9 ## What is a taxonomy?
10
11 Hugo includes support for user-defined groupings of content called **taxonomies**. Taxonomies are classifications of logical relationships between content.
12
13 ### Definitions
14
15 Taxonomy
16 : A categorization that can be used to classify content
17
18 Term
19 : A key within the taxonomy
20
21 Value
22 : A piece of content assigned to a term
23
24 ## Example taxonomy: movie website
25
26 Let's assume you are making a website about movies. You may want to include the following taxonomies:
27
28 - Actors
29 - Directors
30 - Studios
31 - Genre
32 - Year
33 - Awards
34
35 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.
36
37 ### Movie taxonomy organization
38
39 To continue with the example of a movie site, the following demonstrates content relationships from the perspective of the taxonomy:
40
41 ```txt
42 Actor <- Taxonomy
43 Bruce Willis <- Term
44 The Sixth Sense <- Value
45 Unbreakable <- Value
46 Moonrise Kingdom <- Value
47 Samuel L. Jackson <- Term
48 Unbreakable <- Value
49 The Avengers <- Value
50 xXx <- Value
51 ```
52
53 From the perspective of the content, the relationships would appear differently, although the data and labels used are the same:
54
55 ```txt
56 Unbreakable <- Value
57 Actors <- Taxonomy
58 Bruce Willis <- Term
59 Samuel L. Jackson <- Term
60 Director <- Taxonomy
61 M. Night Shyamalan <- Term
62 ...
63 Moonrise Kingdom <- Value
64 Actors <- Taxonomy
65 Bruce Willis <- Term
66 Bill Murray <- Term
67 Director <- Taxonomy
68 Wes Anderson <- Term
69 ...
70 ```
71
72 ### Default destinations
73
74 When taxonomies are used 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:
75
76 - A single page at `example.com/categories/` that lists all the terms within the taxonomy
77 - Individual taxonomy list pages (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
78
79 ## Configuration
80
81 See [configure taxonomies][].
82
83 ## Assign terms to content
84
85 To assign one or more terms to a page, create a front matter field using the plural name of the taxonomy, then add terms to the corresponding array. For example:
86
87 {{< code-toggle file=content/example.md fm=true >}}
88 title = 'Example'
89 tags = ['Tag A','Tag B']
90 categories = ['Category A','Category B']
91 {{< /code-toggle >}}
92
93 ## Taxonomic weight
94
95 {{% glossary-term "taxonomic weight" %}}
96
97 Assign a taxonomic weight using a front matter key named `[taxonomy_name]_weight`.
98
99 {{< code-toggle file="content/courses/organic-chemistry.md" fm=true >}}
100 title = 'Organic Chemistry'
101 weight = 10
102 tags_weight = 1000
103 tags = ['chemistry','science']
104 {{</ code-toggle >}}
105
106 With the front matter above, the `organic-chemistry` page will float towards the top of the list on section and home pages, and it will sink towards the bottom of the list on the `chemistry` and `science` term pages.
107
108 ## Metadata
109
110 Display metadata about each term by creating a corresponding branch bundle in the `content` directory.
111
112 For example, create an `authors` taxonomy:
113
114 {{< code-toggle file=hugo >}}
115 [taxonomies]
116 author = 'authors'
117 {{< /code-toggle >}}
118
119 Then create content with one [branch bundle](g) for each term:
120
121 ```tree
122 content/
123 └── authors/
124 ├── jsmith/
125 │ ├── _index.md
126 │ └── portrait.jpg
127 └── rjones/
128 ├── _index.md
129 └── portrait.jpg
130 ```
131
132 Then add front matter to each term page:
133
134 {{< code-toggle file=content/authors/jsmith/_index.md fm=true >}}
135 title = 'John Smith'
136 affiliation = 'University of Chicago'
137 {{< /code-toggle >}}
138
139 Then create a _taxonomy_ template specific to the `authors` taxonomy:
140
141 ```go-html-template {file="layouts/authors/taxonomy.html"}
142 {{ define "main" }}
143 <h1>{{ .Title }}</h1>
144 {{ .Content }}
145 {{ range .Data.Terms.Alphabetical }}
146 <h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a></h2>
147 <p>Affiliation: {{ .Page.Params.Affiliation }}</p>
148 {{ with .Page.Resources.Get "portrait.jpg" }}
149 {{ with .Fill "100x100" }}
150 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="portrait">
151 {{ end }}
152 {{ end }}
153 {{ end }}
154 {{ end }}
155 ```
156
157 In the example above we list each author including their affiliation and portrait.
158
159 Or create a _term_ template specific to the `authors` taxonomy:
160
161 ```go-html-template {file="layouts/authors/term.html"}
162 {{ define "main" }}
163 <h1>{{ .Title }}</h1>
164 <p>Affiliation: {{ .Params.affiliation }}</p>
165 {{ with .Resources.Get "portrait.jpg" }}
166 {{ with .Fill "100x100" }}
167 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="portrait">
168 {{ end }}
169 {{ end }}
170 {{ .Content }}
171 {{ range .Pages }}
172 <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
173 {{ end }}
174 {{ end }}
175 ```
176
177 In the example above we display the author including their affiliation and portrait, then a list of associated content.
178
179 [configure taxonomies]: /configuration/taxonomies/