mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
---
|
||||
title: Taxonomy templates
|
||||
description: Create a taxonomy template to render a list of terms.
|
||||
categories: [templates]
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 90
|
||||
weight: 90
|
||||
toc: true
|
||||
weight: 80
|
||||
aliases: [/taxonomies/displaying/,/templates/terms/,/indexes/displaying/,/taxonomies/templates/,/indexes/ordering/, /templates/taxonomies/, /templates/taxonomy-templates/]
|
||||
---
|
||||
|
||||
@@ -16,7 +11,7 @@ The [taxonomy](g) template below inherits the site's shell from the [base templa
|
||||
|
||||
[base template]: /templates/types/
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
```go-html-template {file="layouts/_default/taxonomy.html"}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
@@ -24,7 +19,7 @@ The [taxonomy](g) template below inherits the site's shell from the [base templa
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
Review the [template lookup order] to select a template path that provides the desired level of specificity.
|
||||
|
||||
@@ -69,7 +64,7 @@ Once we have the `Taxonomy` object, we can call any of its [methods], allowing u
|
||||
|
||||
The taxonomy template below inherits the site's shell from the base template, and renders a list of terms in the current taxonomy. Hugo sorts the list alphabetically by term, and displays the number of pages associated with each term.
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
```go-html-template {file="layouts/_default/taxonomy.html"}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
@@ -77,13 +72,13 @@ The taxonomy template below inherits the site's shell from the base template, an
|
||||
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
## Sort by term count
|
||||
|
||||
The taxonomy template below inherits the site's shell from the base template, and renders a list of terms in the current taxonomy. Hugo sorts the list by the number of pages associated with each term, and displays the number of pages associated with each term.
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
```go-html-template {file="layouts/_default/taxonomy.html"}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
@@ -91,7 +86,7 @@ The taxonomy template below inherits the site's shell from the base template, an
|
||||
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
## Include content links
|
||||
|
||||
@@ -102,7 +97,7 @@ The [`Alphabetical`] and [`ByCount`] methods used in the previous examples retur
|
||||
|
||||
The taxonomy template below inherits the site's shell from the base template, and renders a list of terms in the current taxonomy. Hugo sorts the list by the number of pages associated with each term, displays the number of pages associated with each term, then lists the content to which each term is assigned.
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
```go-html-template {file="layouts/_default/taxonomy.html"}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
@@ -115,7 +110,7 @@ The taxonomy template below inherits the site's shell from the base template, an
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
## Display metadata
|
||||
|
||||
@@ -150,7 +145,7 @@ affiliation = "University of Chicago"
|
||||
|
||||
Then create a taxonomy template specific to the "authors" taxonomy:
|
||||
|
||||
{{< code file=layouts/authors/taxonomy.html >}}
|
||||
```go-html-template {file="layouts/authors/taxonomy.html"}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
@@ -164,6 +159,6 @@ Then create a taxonomy template specific to the "authors" taxonomy:
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
In the example above we list each author including their affiliation and portrait.
|
||||
|
Reference in New Issue
Block a user