2014-05-27 18:32:57 -04:00
|
|
|
|
---
|
2014-05-29 18:42:05 -04:00
|
|
|
|
aliases:
|
|
|
|
|
- /indexes/lists/
|
|
|
|
|
- /doc/indexes/
|
|
|
|
|
- /extras/indexes
|
2016-01-06 17:45:19 -05:00
|
|
|
|
lastmod: 2015-09-15
|
2014-05-29 18:42:05 -04:00
|
|
|
|
date: 2014-05-21
|
|
|
|
|
linktitle: Taxonomy Terms
|
2014-05-27 18:32:57 -04:00
|
|
|
|
menu:
|
|
|
|
|
main:
|
2014-05-29 18:42:05 -04:00
|
|
|
|
parent: layout
|
|
|
|
|
next: /templates/views
|
|
|
|
|
prev: /templates/homepage
|
|
|
|
|
title: Taxonomy Terms Template
|
|
|
|
|
weight: 60
|
2015-05-22 14:46:09 -04:00
|
|
|
|
toc: true
|
2014-05-27 18:32:57 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
A unique template is needed to create a list of the terms for a given
|
|
|
|
|
taxonomy. This is different from the [list template](/templates/list/)
|
2015-01-29 14:34:56 -05:00
|
|
|
|
as that template is a list of content, whereas this is a list of meta data.
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
## Which Template will be rendered?
|
|
|
|
|
Hugo uses a set of rules to figure out which template to use when
|
|
|
|
|
rendering a specific page.
|
|
|
|
|
|
2015-01-29 14:34:56 -05:00
|
|
|
|
A Taxonomy Terms List will be rendered at /`PLURAL`/
|
|
|
|
|
(e.g. http://spf13.com/topics/)
|
|
|
|
|
from the following prioritized list:
|
|
|
|
|
|
|
|
|
|
* /layouts/taxonomy/`SINGULAR`.terms.html (e.g. `/layouts/taxonomy/topic.terms.html`)
|
|
|
|
|
* /layouts/\_default/terms.html
|
|
|
|
|
|
|
|
|
|
If a file isn’t present,
|
2014-09-03 00:12:26 -04:00
|
|
|
|
then the next one in the list will be used. This enables you to craft
|
2014-05-27 18:32:57 -04:00
|
|
|
|
specific layouts when you want to without creating more templates
|
2015-01-27 21:17:09 -05:00
|
|
|
|
than necessary. For most sites, only the `_default` file at the end of
|
2014-05-27 18:32:57 -04:00
|
|
|
|
the list will be needed.
|
|
|
|
|
|
|
|
|
|
If that neither file is found in either the /layouts or /theme/layouts
|
2015-01-27 21:17:09 -05:00
|
|
|
|
directory, then Hugo will not render the taxonomy terms pages. It is also
|
2014-05-27 18:32:57 -04:00
|
|
|
|
common for people to render taxonomy terms lists on other pages such as
|
|
|
|
|
the homepage or the sidebar (such as a tag cloud) and not have a
|
|
|
|
|
dedicated page for the terms.
|
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
|
2014-05-27 18:32:57 -04:00
|
|
|
|
## Variables
|
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
Taxonomy Terms pages are of the type "node" and have all the
|
|
|
|
|
[node variables](/templates/variables/) and
|
|
|
|
|
[site variables](/templates/variables/)
|
|
|
|
|
available to use in the templates.
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
Taxonomy Terms pages will additionally have:
|
|
|
|
|
|
2014-09-03 00:12:26 -04:00
|
|
|
|
* **.Data.Singular** The singular name of the taxonomy
|
|
|
|
|
* **.Data.Plural** The plural name of the taxonomy
|
|
|
|
|
* **.Data.Terms** The taxonomy itself
|
|
|
|
|
* **.Data.Terms.Alphabetical** The Terms alphabetized
|
|
|
|
|
* **.Data.Terms.ByCount** The Terms ordered by popularity
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-05-12 12:46:45 -04:00
|
|
|
|
The last two can also be reversed: **.Data.Terms.Alphabetical.Reverse**, **.Data.Terms.ByCount.Reverse**.
|
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
### Example terms.html files
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
List pages are of the type "node" and have all the
|
|
|
|
|
[node variables](/templates/variables/) and
|
|
|
|
|
[site variables](/templates/variables/)
|
|
|
|
|
available to use in the templates.
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
This content template is used for [spf13.com](http://spf13.com/).
|
2015-01-29 14:34:56 -05:00
|
|
|
|
It makes use of [partial templates](/templates/partials/). The list of taxonomy
|
2015-01-27 21:17:09 -05:00
|
|
|
|
templates cannot use a [content view](/templates/views/) as they don't display the content, but
|
2014-05-27 18:32:57 -04:00
|
|
|
|
rather information about the content.
|
|
|
|
|
|
|
|
|
|
This particular template lists all of the Tags used on
|
2015-01-27 21:17:09 -05:00
|
|
|
|
[spf13.com](http://spf13.com/) and provides a count for the number of pieces of
|
2014-05-27 18:32:57 -04:00
|
|
|
|
content tagged with each tag.
|
|
|
|
|
|
2015-09-15 14:31:11 -04:00
|
|
|
|
`.Data.Terms` is a map of terms ⇒ [contents]
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2014-06-06 16:15:19 -04:00
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<div>
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<ul>
|
|
|
|
|
{{ $data := .Data }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
{{ range $key, $value := .Data.Terms }}
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<li><a href="{{ $data.Plural }}/{{ $key | urlize }}">{{ $key }}</a> {{ len $value }}</li>
|
2014-05-27 18:32:57 -04:00
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
2015-01-31 09:27:42 -05:00
|
|
|
|
{{ partial "footer.html" . }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
Another example listing the content for each term (ordered by Date):
|
2014-08-29 23:41:53 -04:00
|
|
|
|
|
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<div>
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
2014-08-29 23:41:53 -04:00
|
|
|
|
|
|
|
|
|
{{ $data := .Data }}
|
|
|
|
|
{{ range $key,$value := .Data.Terms.ByCount }}
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<h2><a href="{{ $data.Plural }}/{{ $value.Name | urlize }}">{{ $value.Name }}</a> {{ $value.Count }}</h2>
|
2014-08-29 23:41:53 -04:00
|
|
|
|
<ul>
|
2015-01-27 21:17:09 -05:00
|
|
|
|
{{ range $value.Pages.ByDate }}
|
|
|
|
|
<li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
|
|
|
|
|
{{ end }}
|
2014-08-29 23:41:53 -04:00
|
|
|
|
</ul>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
2015-01-31 09:27:42 -05:00
|
|
|
|
{{ partial "footer.html" . }}
|
2014-08-29 23:41:53 -04:00
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
|
2014-05-27 18:32:57 -04:00
|
|
|
|
## Ordering
|
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
Hugo can order the meta data in two different ways. It can be ordered:
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
* by the number of contents assigned to that key, or
|
|
|
|
|
* alphabetically.
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
### Example terms.html file (alphabetical)
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2014-06-06 16:15:19 -04:00
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<div>
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
|
|
|
|
<ul>
|
|
|
|
|
{{ $data := .Data }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
{{ range $key, $value := .Data.Terms.Alphabetical }}
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<li><a href="{{ $data.Plural }}/{{ $value.Name | urlize }}">{{ $value.Name }}</a> {{ $value.Count }}</li>
|
2014-05-27 18:32:57 -04:00
|
|
|
|
{{ end }}
|
2015-01-27 21:17:09 -05:00
|
|
|
|
</ul>
|
2014-05-27 18:32:57 -04:00
|
|
|
|
</div>
|
|
|
|
|
</section>
|
2015-01-31 09:27:42 -05:00
|
|
|
|
{{ partial "footer.html" . }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-27 21:17:09 -05:00
|
|
|
|
### Example terms.html file (ordered by popularity)
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2014-06-06 16:15:19 -04:00
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<div>
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
|
|
|
|
<ul>
|
|
|
|
|
{{ $data := .Data }}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
{{ range $key, $value := .Data.Terms.ByCount }}
|
2015-01-27 21:17:09 -05:00
|
|
|
|
<li><a href="{{ $data.Plural }}/{{ $value.Name | urlize }}">{{ $value.Name }}</a> {{ $value.Count }}</li>
|
2014-05-27 18:32:57 -04:00
|
|
|
|
{{ end }}
|
2015-01-27 21:17:09 -05:00
|
|
|
|
</ul>
|
2014-05-27 18:32:57 -04:00
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
2015-01-31 09:27:42 -05:00
|
|
|
|
{{ partial "footer.html" . }}
|