Taxonomies.md - hugo - [fork] hugo port for 9front
(HTM) git clone https://git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
Taxonomies.md (4553B)
---
1 ---
2 title: Taxonomies
3 description: Returns a data structure containing the site's Taxonomy objects, the terms within each Taxonomy object, and the pages to which the terms are assigned.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.TaxonomyList
9 signatures: [SITE.Taxonomies]
10 ---
11
12 Conceptually, the `Taxonomies` method on a `Site` object returns a data structure such as:
13
14 {{< code-toggle file=hugo >}}
15 taxonomy a:
16 - term 1:
17 - page 1
18 - page 2
19 - term 2:
20 - page 1
21 taxonomy b:
22 - term 1:
23 - page 2
24 - term 2:
25 - page 1
26 - page 2
27 {{< /code-toggle >}}
28
29 For example, on a book review site you might create two taxonomies; one for genres and another for authors.
30
31 With this site configuration:
32
33 {{< code-toggle file=hugo >}}
34 [taxonomies]
35 genre = 'genres'
36 author = 'authors'
37 {{< /code-toggle >}}
38
39 And this content structure:
40
41 ```text
42 content/
43 ├── books/
44 │ ├── and-then-there-were-none.md --> genres: suspense
45 │ ├── death-on-the-nile.md --> genres: suspense
46 │ └── jamaica-inn.md --> genres: suspense, romance
47 │ └── pride-and-prejudice.md --> genres: romance
48 └── _index.md
49 ```
50
51 Conceptually, the taxonomies data structure looks like:
52
53 {{< code-toggle file=hugo >}}
54 genres:
55 - suspense:
56 - And Then There Were None
57 - Death on the Nile
58 - Jamaica Inn
59 - romance:
60 - Jamaica Inn
61 - Pride and Prejudice
62 authors:
63 - achristie:
64 - And Then There Were None
65 - Death on the Nile
66 - ddmaurier:
67 - Jamaica Inn
68 - jausten:
69 - Pride and Prejudice
70 {{< /code-toggle >}}
71
72 To list the "suspense" books:
73
74 ```go-html-template
75 <ul>
76 {{ range .Site.Taxonomies.genres.suspense }}
77 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
78 {{ end }}
79 </ul>
80 ```
81
82 Hugo renders this to:
83
84 ```html
85 <ul>
86 <li><a href="/books/and-then-there-were-none/">And Then There Were None</a></li>
87 <li><a href="/books/death-on-the-nile/">Death on the Nile</a></li>
88 <li><a href="/books/jamaica-inn/">Jamaica Inn</a></li>
89 </ul>
90 ```
91
92 > [!note]
93 > Hugo's taxonomy system is powerful, allowing you to classify content and create relationships between pages.
94 >
95 > Please see the [taxonomies] section for a complete explanation and examples.
96
97 ## Examples
98
99 ### List content with the same taxonomy term
100
101 If you are using a taxonomy for something like a series of posts, you can list individual pages associated with the same term. For example:
102
103 ```go-html-template
104 <ul>
105 {{ range .Site.Taxonomies.series.golang }}
106 <li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></li>
107 {{ end }}
108 </ul>
109 ```
110
111 ### List all content in a given taxonomy
112
113 This would be very useful in a sidebar as “featured content”. You could even have different sections of “featured content” by assigning different terms to the content.
114
115 ```go-html-template
116 <section id="menu">
117 <ul>
118 {{ range $term, $taxonomy := .Site.Taxonomies.featured }}
119 <li>{{ $term }}</li>
120 <ul>
121 {{ range $taxonomy.Pages }}
122 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
123 {{ end }}
124 </ul>
125 {{ end }}
126 </ul>
127 </section>
128 ```
129
130 ### Render a site's taxonomies
131
132 The following example displays all terms in a site's tags taxonomy:
133
134 ```go-html-template
135 <ul>
136 {{ range .Site.Taxonomies.tags }}
137 <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
138 {{ end }}
139 </ul>
140 ```
141 This example will list all taxonomies and their terms, as well as all the content assigned to each of the terms.
142
143 ```go-html-template {file="layouts/_partials/all-taxonomies.html"}
144 {{ with .Site.Taxonomies }}
145 {{ $numberOfTerms := 0 }}
146 {{ range $taxonomy, $terms := . }}
147 {{ $numberOfTerms = len . | add $numberOfTerms }}
148 {{ end }}
149
150 {{ if gt $numberOfTerms 0 }}
151 <ul>
152 {{ range $taxonomy, $terms := . }}
153 {{ with $terms }}
154 <li>
155 <a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
156 <ul>
157 {{ range $term, $weightedPages := . }}
158 <li>
159 <a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
160 <ul>
161 {{ range $weightedPages }}
162 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
163 {{ end }}
164 </ul>
165 </li>
166 {{ end }}
167 </ul>
168 </li>
169 {{ end }}
170 {{ end }}
171 </ul>
172 {{ end }}
173 {{ end }}
174 ```
175
176 [taxonomies]: /content-management/taxonomies/