hugo/docs/content/en/templates/taxonomy-templates.md

342 lines
12 KiB
Markdown
Raw Normal View History

---
title: Taxonomy Templates
# linktitle:
description: Taxonomy templating includes taxonomy list pages, taxonomy terms pages, and using taxonomies in your single page templates.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [templates]
keywords: [taxonomies,metadata,front matter,terms,templates]
menu:
docs:
parent: "templates"
weight: 50
weight: 50
sections_weight: 50
draft: false
aliases: [/taxonomies/displaying/,/templates/terms/,/indexes/displaying/,/taxonomies/templates/,/indexes/ordering/, /templates/taxonomies/, /templates/taxonomy/]
toc: true
---
<!-- NOTE! Check on https://github.com/gohugoio/hugo/issues/2826 for shifting of terms' pages to .Data.Pages AND
https://discourse.gohugo.io/t/how-to-specify-category-slug/4856/15 for original discussion.-->
Hugo includes support for user-defined groupings of content called **taxonomies**. Taxonomies are classifications that demonstrate logical relationships between content. See [Taxonomies under Content Management](/content-management/taxonomies) if you are unfamiliar with how Hugo leverages this powerful feature.
Hugo provides multiple ways to use taxonomies throughout your project templates:
* Order the way content associated with a taxonomy term is displayed in a [taxonomy list template](#taxonomy-list-templates)
* Order the way the terms for a taxonomy are displayed in a [taxonomy terms template](#taxonomy-terms-templates)
* List a single content's taxonomy terms within a [single page template]
## Taxonomy List Templates
Taxonomy list page templates are lists and therefore have all the variables and methods available to [list pages][lists].
### Taxonomy List Template Lookup Order
See [Template Lookup](/templates/lookup-order/).
## Taxonomy Terms Templates
### Taxonomy Terms Templates Lookup Order
See [Template Lookup](/templates/lookup-order/).
### Taxonomy Methods
A Taxonomy is a `map[string]WeightedPages`.
.Get(term)
: Returns the WeightedPages for a term.
.Count(term)
: The number of pieces of content assigned to this term.
.Alphabetical
: Returns an OrderedTaxonomy (slice) ordered by Term.
.ByCount
: Returns an OrderedTaxonomy (slice) ordered by number of entries.
.Reverse
: Returns an OrderedTaxonomy (slice) in reverse order. Must be used with an OrderedTaxonomy.
### OrderedTaxonomy
Since Maps are unordered, an OrderedTaxonomy is a special structure that has a defined order.
```go
[]struct {
Name string
WeightedPages WeightedPages
}
```
Each element of the slice has:
.Term
: The Term used.
.WeightedPages
: A slice of Weighted Pages.
.Count
: The number of pieces of content assigned to this term.
.Pages
: All Pages assigned to this term. All [list methods][renderlists] are available to this.
## WeightedPages
WeightedPages is simply a slice of WeightedPage.
```go
type WeightedPages []WeightedPage
```
.Count(term)
: The number of pieces of content assigned to this term.
.Pages
: Returns a slice of pages, which then can be ordered using any of the [list methods][renderlists].
## Displaying custom metadata in Taxonomy Terms Templates
If you need to display custom metadata for each taxonomy term, you will need to create a page for that term at `/content/<TAXONOMY>/<TERM>/_index.md` and add your metadata in its front matter, [as explained in the taxonomies documentation](/content-management/taxonomies/#add-custom-metadata-to-a-taxonomy-or-term). Based on the Actors taxonomy example shown there, within your taxonomy terms template, you may access your custom fields by iterating through the variable `.Pages` as such:
```go-html-template
<ul>
{{ range .Pages }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
{{ .Params.wikipedia }}
</li>
{{ end }}
</ul>
```
<!-- Begin /taxonomies/ordering/ -->
## Order Taxonomies
Taxonomies can be ordered by either alphabetical key or by the number of content pieces assigned to that key.
### Order Alphabetically Example
```go-html-template
<ul>
{{ range .Data.Terms.Alphabetical }}
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
{{ end }}
</ul>
```
<!-- [See Also Taxonomy Lists](/templates/list/) -->
## Order Content within Taxonomies
Hugo uses both `date` and `weight` to order content within taxonomies.
Each piece of content in Hugo can optionally be assigned a date. It can also be assigned a weight for each taxonomy it is assigned to.
Squashed 'docs/' changes from 4895c29c5..9abd3043a 9abd3043a Add docs for shimming JS libraries 6a1c8dcd7 Update sitemap-template.md (#1245) 37c397332 Update frontends.md a0f86f6df Update configuration.md bb00cb2c1 Update page-bundles.md 773212de6 Restructure and simplify fcba7dddf Some minor clarifications of weight sorting 759b967fc Update configuration-markup.md 56708f0b7 module import path remove slash at end 59f4f4acd Doc: Fix typo in hugo command faacf2e97 Clarify pagination documentation (#1208) d8eb60887 netlify: Bump to 0.75.1 8cedf6231 Merge branch 'temp751' 188e2bf56 releaser: Add release notes to /docs for release of 0.75.1 c96d4b7a3 Update index.md 1a9d192f7 Update index.md 32731b916 Update index.md a5bfa0c9a Restore the ... home page b6850bf96 Release 0.75.0 d6e5e624f releaser: Add release notes to /docs for release of 0.75.0 8cd6b4f47 typo: already -> already 2cb2b22bb Merge commit '534ae9c57a902aea9ed6e62390dec11fa74b7122' e3525de23 docs: Regen docs helper fd746dd83 docs: Regenerate CLI docs e20127980 Add "hugo mod npm pack" 8e82c7ce1 markup/highlight: Add support to linkable line anchors on Chroma 21e94911b markup/asciidocext: Fix AsciiDoc TOC with code 50b8dace5 modules: Add noVendor to module config d05b541fe modules: Make ignoreVendor a glob pattern c946082e7 docs: Update replaceRE func 149054341 docs: Update replace func d917567df docs: Update merge function f1e093c92 docs: Regen CLI docs c7bac967d docs: Regen docs helper 7a38f7a45 Merge commit '7d7771b673e5949f554515a2c236b23192c765c8' 1a5a7263a markup/asciidoc: Add support for .TableOfContents git-subtree-dir: docs git-subtree-split: 9abd3043a9214b390e8cc148f4588bf630620851
2020-10-06 14:22:20 +00:00
When iterating over content within taxonomies, the default sort is the same as that used for section and list pages: first by weight, then by date. This means that if the weights for two pieces of content are the same, then the more recent content will be displayed first.
Squashed 'docs/' changes from 4895c29c5..9abd3043a 9abd3043a Add docs for shimming JS libraries 6a1c8dcd7 Update sitemap-template.md (#1245) 37c397332 Update frontends.md a0f86f6df Update configuration.md bb00cb2c1 Update page-bundles.md 773212de6 Restructure and simplify fcba7dddf Some minor clarifications of weight sorting 759b967fc Update configuration-markup.md 56708f0b7 module import path remove slash at end 59f4f4acd Doc: Fix typo in hugo command faacf2e97 Clarify pagination documentation (#1208) d8eb60887 netlify: Bump to 0.75.1 8cedf6231 Merge branch 'temp751' 188e2bf56 releaser: Add release notes to /docs for release of 0.75.1 c96d4b7a3 Update index.md 1a9d192f7 Update index.md 32731b916 Update index.md a5bfa0c9a Restore the ... home page b6850bf96 Release 0.75.0 d6e5e624f releaser: Add release notes to /docs for release of 0.75.0 8cd6b4f47 typo: already -> already 2cb2b22bb Merge commit '534ae9c57a902aea9ed6e62390dec11fa74b7122' e3525de23 docs: Regen docs helper fd746dd83 docs: Regenerate CLI docs e20127980 Add "hugo mod npm pack" 8e82c7ce1 markup/highlight: Add support to linkable line anchors on Chroma 21e94911b markup/asciidocext: Fix AsciiDoc TOC with code 50b8dace5 modules: Add noVendor to module config d05b541fe modules: Make ignoreVendor a glob pattern c946082e7 docs: Update replaceRE func 149054341 docs: Update replace func d917567df docs: Update merge function f1e093c92 docs: Regen CLI docs c7bac967d docs: Regen docs helper 7a38f7a45 Merge commit '7d7771b673e5949f554515a2c236b23192c765c8' 1a5a7263a markup/asciidoc: Add support for .TableOfContents git-subtree-dir: docs git-subtree-split: 9abd3043a9214b390e8cc148f4588bf630620851
2020-10-06 14:22:20 +00:00
The default weight for any piece of content is 0. Zero means "does not have a weight", not "has a weight of numerical value zero".
Squashed 'docs/' changes from 4895c29c5..9abd3043a 9abd3043a Add docs for shimming JS libraries 6a1c8dcd7 Update sitemap-template.md (#1245) 37c397332 Update frontends.md a0f86f6df Update configuration.md bb00cb2c1 Update page-bundles.md 773212de6 Restructure and simplify fcba7dddf Some minor clarifications of weight sorting 759b967fc Update configuration-markup.md 56708f0b7 module import path remove slash at end 59f4f4acd Doc: Fix typo in hugo command faacf2e97 Clarify pagination documentation (#1208) d8eb60887 netlify: Bump to 0.75.1 8cedf6231 Merge branch 'temp751' 188e2bf56 releaser: Add release notes to /docs for release of 0.75.1 c96d4b7a3 Update index.md 1a9d192f7 Update index.md 32731b916 Update index.md a5bfa0c9a Restore the ... home page b6850bf96 Release 0.75.0 d6e5e624f releaser: Add release notes to /docs for release of 0.75.0 8cd6b4f47 typo: already -> already 2cb2b22bb Merge commit '534ae9c57a902aea9ed6e62390dec11fa74b7122' e3525de23 docs: Regen docs helper fd746dd83 docs: Regenerate CLI docs e20127980 Add "hugo mod npm pack" 8e82c7ce1 markup/highlight: Add support to linkable line anchors on Chroma 21e94911b markup/asciidocext: Fix AsciiDoc TOC with code 50b8dace5 modules: Add noVendor to module config d05b541fe modules: Make ignoreVendor a glob pattern c946082e7 docs: Update replaceRE func 149054341 docs: Update replace func d917567df docs: Update merge function f1e093c92 docs: Regen CLI docs c7bac967d docs: Regen docs helper 7a38f7a45 Merge commit '7d7771b673e5949f554515a2c236b23192c765c8' 1a5a7263a markup/asciidoc: Add support for .TableOfContents git-subtree-dir: docs git-subtree-split: 9abd3043a9214b390e8cc148f4588bf630620851
2020-10-06 14:22:20 +00:00
Weights of zero are thus treated specially: if two pages have unequal weights, and one of them is zero, then the zero-weighted page will always appear after the other one, regardless of the other's weight. Zero weights should thus be used with care: for example, if both positive and negative weights are used to extend a sequence in both directions, a zero-weighted page will appear not in the middle of the list, but at the end.
### Assign Weight
Content can be assigned weight for each taxonomy that it's assigned to.
Squashed 'docs/' changes from 392668f4f..32cb8785e 32cb8785e Fix page weights in content management section (#1896) 11977b96f Make relURL and related functions consistent (#1895) f12180207 Clarify github deployment (#1894) 958877789 Remove remaining references to Highlight.js (#1893) fc487d263 Minor edit to taxonomy page 3b6a224b2 Update theme b28553b62 Change "flavor" to "edition" when referring to builds (#1892) 660e7581c Replaced sudo in OpenBSD with doas (#1891) e3fcdea10 fix a few minor grammatical issues on Firebase docs (#1889) e4c8b30eb update Static Web Apps docs (#1890) da2197c9e Update hosting-on-firebase.md (#1347) 5f2a0c271 Adding deployment guide for Azure Static Web Apps (#1456) 5aaf570cd add Azure Static Web App config to 404 template 35fc54362 add Azure Static Web App config to 404 template d48f67ba1 Update 01-flavors.md 11debae8d Cleaned Use of ref and relref section, added refs of index.md and _in… (#1744) b77604078 docs: Add link to menu entry variables (#1827) 0fa8a6bf0 Misc copy edits (#1887) c27b545ac Improve explanation of safeHTMLAttr's function (#1503) b04a4b32e Make CLI command summaries meaningful (#1886) dbf00a81f Fix a typo in diagrams documentation (#1885) 11f884327 docs: Clarify how to remove draft/future/expired content (#1831) 6dc9e9860 Improve complement function (#1884) 56448a51a Remove erroneous sourcemap desc (#1883) a0d0d2829 Merge branch 'divinerites-patch-1' 10f20cb5e Add a plausible-hugo theme component 9f1413eb5 Minor edits to showcase example 7d78420db fix broken link to Isso Comments 925cb291f Make directory tree consistent with other examples 300fff092 Add link to security policy from getenv.md (#1746) 7b4c517a6 Fix docs menu weights ce35775e0 Update faq.md (#1763) f3fb791a4 Remove dated new-in flags (#1879) b6c634629 Remove deprecated templating langs (#1880) 1b25ca34f Update the findRE and replaceRE functions (#1881) 28757ec73 Add Alora Labs website to showcase (#1494) e3c4bc4e7 Remove unimplemented "ugly" property 86afd84ff Update editors.md (#1878) 44c093911 Add urlquery function docs (#1633) 16a8c3548 Update links to installation page (#1876) 9e357f078 Add missing sections to BSD installation page (#1875) 1b1291634 Promote "Installation" to a section 9dd51235b Add detail to description of .Plain page variable (#1870) d333d0287 Minor markdown linting fix and URL updates (#1873) d57c8aa50 Remove extraneous apostrophe (#1871) 8c25cfc5c Update index.md 09fea41e0 Add lang to fenced code block 35b904798 Add small documentation about .Site.Social.twitter variable (#1854) 672042f89 Consolidate site configuration dfd4dd873 Add help.ampio.com showcase. (#1863) e8d0e7bdf Include link to internal templates code (#1794) 7db6f0c01 Add example to split function (#1867) be87dba80 Clarify split function docs (#1792) a079193f1 Fix typo on data templates page b234c70ee Fix data templates page (#1855) 074232b45 Update front-matter.md (#1856) 711c8fa80 Added missing default value (#1862) 034762882 Fixed some grammar issues and typos (#1865) 764574a4d Fix spelling error 2698f2d44 update URLs to prevent redirects (#1864) 68f05fdc8 Fenced code blocks should have a language specified (#1861) 24393315b GitHub Workflows security hardening (#1859) 3eeee13bf Markdown formatting: Add Fenced code block languages (#1858) e152cdf1f netlify: Hugo 0.105.0 4c7fc9f7e Merge branch 'tempv0.105.0' d16710afc Change anchor reference to use relref function calls (#1853) f52af8e4a tpl/encoding: Add noHTMLEscape option to jsonify eca0046c4 Update hosting-on-keycdn docs (#1852) ffbe17a48 Add note for rsync deploy command (#1415) c482133f1 docs: Update quick start to clarify the need of extended version (#1828) 1e3b33804 use correct URL for Google Search console verification (#1851) dac034f63 Markdown and formatting fixes (#1850) 43f177e3c Fix LiveReload in quick-start (#1739) f78deaa5f Add link for ''Hugo Shortcode Syntax Highlighting' VS Code extension (#1765) 08087ecd7 Remove some hidden pages (#1848) b6cb5ae48 Markdown linting fixes (#1846) 527ec5941 Update hugo.md (#1742) 83e8f2168 Clarify that a shortcode with .Inner must be closed (#1785) 4193f4445 Add Super Linter GitHub Action (#1845) fd91bfe1a Formatting and grammar fixes (#1844) ab5a49c49 Create codeql-analysis GitHub Action (#1812) 63b3e082e Add tutorial on using fusejs to search examples (#1756) 54c253ab0 Note that Google Universal Analytics are deprecated (#1770) 385fa77c6 Update articles.toml (#1840) 5e336bd26 Replace awkward wording (ESL?) (#1842) 2446ad349 Added Introduction to Hugo tutorial/video series (#1736) 7b21b2e76 Don't use self-closing generator tag ef73712ff Image processing. available methods: add method 'Colors' (#1837) 018f83bbe [comment platform] - add new alternative (#1751) 5636c208b Grammar and spelling fixes (#1836) 3f2e26f77 Change link of repojacking vulnerable link - JekyllToHugo (#1834) 301379fc3 fix: use shorter image URL to make it easier to read (#1835) de5fa7b30 Update search.md to include Pagefind (#1826) e9d72bcda Breadcrumb example: add basic accessibility (#1832) 6cffff87a netlify: Hugo 0.104.3 892360f61 Update output-formats.md 09a7a46ae Remove my defunct and little used migrator (#1824) 347434cca netlify: Hugo 0.104.2 f8c721162 Update postcss.md c2baf7155 netlify: Hugo 0.104.1 05d1192cd Update diagrams.md (#1823) 3c43a8bbe netlify: Hugo 0.104.0 57973b334 Merge branch 'tempv0.104.0' da775a36d docs: Regen docs helper ae48b5901 docs: Regenerate CLI docs af4a823b1 resources/images: Add $image.Colors 8e3f9ca64 Remove outdated IE conditional comments example (#1821) d1a84701b fix typo in template introduction (#1820) c0c7339e0 Update internal.md 17aefc515 Remove the recommendation about where to put the GA tempalte 263297236 Adjust GA template instructions 1cc265d99 Update the GA template usage section e11968338 config/security: Allow proxy variables in subcommands 9218ab993 netlify: Hugo 0.103.1 0b0e890d1 Update markdownify and RenderString documentation (#1818) 50f5d4776 Fix internal link (#1817) 6beb443c5 netlify: Hugo 0.103.0 14b5af248 Merge branch 'tempv0.103.0' 548e7aa62 server: Add 404 support 3a20aa0ba Update theme git-subtree-dir: docs git-subtree-split: 32cb8785ea74d5b82f2e2bea79d059cab497902a
2022-11-17 15:14:29 +00:00
```txt
+++
tags = [ "a", "b", "c" ]
tags_weight = 22
categories = ["d"]
title = "foo"
categories_weight = 44
+++
Front Matter with weighted tags and categories
```
The convention is `taxonomyname_weight`.
In the above example, this piece of content has a weight of 22 which applies to the sorting when rendering the pages assigned to the "a", "b" and "c" values of the 'tag' taxonomy.
It has also been assigned the weight of 44 when rendering the 'd' category.
With this the same piece of content can appear in different positions in different taxonomies.
Currently taxonomies only support the default ordering of content which is weight -> date.
<!-- Begin /taxonomies/templates/ -->
There are two different templates that the use of taxonomies will require you to provide.
Both templates are covered in detail in the templates section.
A [list template](/templates/list/) is any template that will be used to render multiple pieces of content in a single html page. This template will be used to generate all the automatically created taxonomy pages.
A [taxonomy terms template](/templates/terms/) is a template used to
generate the list of terms for a given template.
<!-- Begin /taxonomies/displaying/ -->
There are four common ways you can display the data in your
taxonomies in addition to the automatic taxonomy pages created by hugo
using the [list templates](/templates/list/):
1. For a given piece of content, you can list the terms attached
2. For a given piece of content, you can list other content with the same
term
3. You can list all terms for a taxonomy
4. You can list all taxonomies (with their terms)
## Display a Single Piece of Content's Taxonomies
Within your content templates, you may wish to display the taxonomies that piece of content is assigned to.
Because we are leveraging the front matter system to define taxonomies for content, the taxonomies assigned to each content piece are located in the usual place (i.e., `.Params.<TAXONOMYPLURAL>`).
### Example: List Tags in a Single Page Template
Squashed 'docs/' changes from 341ecabb2..988f7d5c2 988f7d5c2 Document default `enableInlineShortcodes` value 0f604a345 Fix typo in 0.66.0 release note 26fc74fe3 How to access individual EXIF data tags d5d3bad9a Fix localhost links fa6921213 Update index.md 5bf558f78 Release 0.66.0 74ccdaaf5 Merge branch 'temp660' 75faa478b releaser: Add release notes to /docs for release of 0.66.0 c4a4a9922 docs: Regen CLI docs 0624ac198 Add build.UseResourceCacheWhen 58a8d7cd1 Add build options documentation d926c595e fix typo 99713d44b resources: Add basic @import support to resources.PostCSS 224b96cf7 deploy: Implement include/exclude filters for deploy eb1a00050 Adjusting description; WordPress with capitalized P 91d8efa22 Add another tool for migration from the Wordpress a6938a4ac Adjust showcase description a9c0a0a69 Adjust showcase e5af08aa6 Adding Aether as a proposed showcase item. 0013daa34 Add hugo.IsProduction function 34c419ef3 tpl: Add math.Sqrt 5bdab0ebd Update minification.md 9039332e2 Hugo 0.65.3 1400caf3a Merge branch 'temp653' 9796bb337 releaser: Add release notes to /docs for release of 0.65.3 65b26598f Fix typo 23aa57d80 Fix crashes for 404 in IsAncestor etc. 42c54bc6c 0.65.2 67fd5c1f6 Merge branch 'temp652' d820ac017 releaser: Add release notes to /docs for release of 0.65.2 51f0888ff Release 0.65.1 91e95260c releaser: Add release notes to /docs for release of 0.65.1 1880ebf05 fix broken link on internal.md ffaa33889 Update migrations.md de4d64675 Another tool for migration from Medium platform 90b178d77 releaser: Add release notes to /docs for release of 0.65.1 6925cda30 Handle corner case with rendering text as code in URL 3cb4b19dd Release 0.65.0 7a600cb99 Merge branch 'temp650' ef9531ff6 releaser: Add release notes to /docs for release of 0.65.0 9bc19606f docs: Regenerate CLI docs d4a886ed2 Add Page.GetTerms a3bf273a5 fix broken link on use-modules.md 001f52f4e Fix mage URL in development.md eef72e887 Merge commit '4b670bc8cc38103c2c60e5090c2f56bf30832b8d' b18a76631 commands: Support "hugo mod get -u ./..." git-subtree-dir: docs git-subtree-split: 988f7d5c2d7a1d40ec2c8ab961cb5a4e41b5bd4c
2020-03-09 19:19:32 +00:00
```go-html-template
<ul>
{{ range (.GetTerms "tags") }}
<li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
Squashed 'docs/' changes from 9cece6640..fb551cc75 fb551cc75 Update index.md 7af894857 Update index.md d235753ea Hugo 0.82.1 e03e72deb Merge branch 'temp0821' e62648961 Merge branch 'release-0.82.1' e1ab0f6eb releaser: Add release notes to /docs for release of 0.82.1 5d354c38d Replaced ``` code blocks with Code Toggler c9d065c20 Remove duplicate YAML keys (#1420) 8ae31e701 Add webp image encoding support 848f2af26 Update internal.md (#1407) c103a86a4 Fix `ref` shortcode example output (#1409) 9f8ba56dc Remove leading dot from where function KEY (#1419) 363251a51 Improve presentation of template lookup order (#1382) b73da986d Improve description of Page Resources (#1381) 4e0bb96d5 Rework robots.txt page (#1405) edf893e6f Update migrations.md (#1412) 450f1580b Add link to `site` function doc (#1417) cfffa6e6f Added one extension to the list (#1414) 05f1665a0 Update theme 5de0b1c6a Update theme 250e20552 Add hugo.IsExtended dea5e1fd7 Fix typo on merge function page (#1408) 1bbed2cf3 Update configuration.md be0b64a46 Omit ISO cbb5b8367 Fix `dateFormat` documentation 698f15466 Regenerate the docshelper f9a8a7cb6 Update multilingual.md a22dc6267 Fix grammar (#1398) eb98b0997 Fix pretty URL example (#1397) f4c4153dc Mention date var complementation in post scheduling (#1396) 17fae284c Fix resources.ExecuteAsTemplate argument order (#1394) 97e2c2abb Use code-toggle shortcode in `multilingual.md` (#1388) 3a84929bb Harmonize capitalization (#1393) 17f15daa6 fix file naming used in example (#1392) 5d97b6a18 Add slice syntax to sections permalinks config 00665b97b Improve description of `site.md` edcf5e3fc Fix example in `merge.md` f275ab778 Update postprocess.md 9593e3991 Fix file name 59bd9656f Update postprocess.md 1172fb6d0 Update to theNewDynamic repository (#1263) f5b5c1d2c Update Hugo container image 4f2e92f2a Adapt anchorize.md to Goldmark 98aa19073 Directly link to `highlight` shortcode (#1384) 4c75c2422 Fix header level f15c06f23 markdownify: add note about render-hooks and .RenderString (#1281) 69c82eb68 Remove Blackfriday reference from shortcode desc (#1380) 36de478df Update description of ignoreFiles config setting (#1377) 6337699d8 Remove "Authors" page from documentation (#1371) 35e73ca90 fix indent in example (#1372) d3f01f19a Remove opening body tag from header example (#1376) 341a5a7d8 Update index.md c9bfdbee6 Release 0.82.0 119644949 releaser: Add release notes to /docs for release of 0.82.0 32efaed78 docs: Regenerate docs helper dea5449a2 docs: Regen CLI docs eeab18fce Merge commit '81689af79901f0cdaff765cda6322dd4a9a7ccb3' d508a1259 Attributes for code fences should be placed after the lang indicator only c80905cef deps: Update to esbuild v0.9.0 95350eb79 Add support for Google Analytics v4 02d36f9bc Allow markdown attribute lists to be used in title render hooks 7df220a64 Merge commit '9d31f650da964a52f05fc27b7fb99cf3e09778cf' d80bf61b7 Fixes #7698. git-subtree-dir: docs git-subtree-split: fb551cc750faa83a1493b0e0d0898cd98ab74465
2021-04-20 18:21:45 +00:00
{{ end }}
Squashed 'docs/' changes from 341ecabb2..988f7d5c2 988f7d5c2 Document default `enableInlineShortcodes` value 0f604a345 Fix typo in 0.66.0 release note 26fc74fe3 How to access individual EXIF data tags d5d3bad9a Fix localhost links fa6921213 Update index.md 5bf558f78 Release 0.66.0 74ccdaaf5 Merge branch 'temp660' 75faa478b releaser: Add release notes to /docs for release of 0.66.0 c4a4a9922 docs: Regen CLI docs 0624ac198 Add build.UseResourceCacheWhen 58a8d7cd1 Add build options documentation d926c595e fix typo 99713d44b resources: Add basic @import support to resources.PostCSS 224b96cf7 deploy: Implement include/exclude filters for deploy eb1a00050 Adjusting description; WordPress with capitalized P 91d8efa22 Add another tool for migration from the Wordpress a6938a4ac Adjust showcase description a9c0a0a69 Adjust showcase e5af08aa6 Adding Aether as a proposed showcase item. 0013daa34 Add hugo.IsProduction function 34c419ef3 tpl: Add math.Sqrt 5bdab0ebd Update minification.md 9039332e2 Hugo 0.65.3 1400caf3a Merge branch 'temp653' 9796bb337 releaser: Add release notes to /docs for release of 0.65.3 65b26598f Fix typo 23aa57d80 Fix crashes for 404 in IsAncestor etc. 42c54bc6c 0.65.2 67fd5c1f6 Merge branch 'temp652' d820ac017 releaser: Add release notes to /docs for release of 0.65.2 51f0888ff Release 0.65.1 91e95260c releaser: Add release notes to /docs for release of 0.65.1 1880ebf05 fix broken link on internal.md ffaa33889 Update migrations.md de4d64675 Another tool for migration from Medium platform 90b178d77 releaser: Add release notes to /docs for release of 0.65.1 6925cda30 Handle corner case with rendering text as code in URL 3cb4b19dd Release 0.65.0 7a600cb99 Merge branch 'temp650' ef9531ff6 releaser: Add release notes to /docs for release of 0.65.0 9bc19606f docs: Regenerate CLI docs d4a886ed2 Add Page.GetTerms a3bf273a5 fix broken link on use-modules.md 001f52f4e Fix mage URL in development.md eef72e887 Merge commit '4b670bc8cc38103c2c60e5090c2f56bf30832b8d' b18a76631 commands: Support "hugo mod get -u ./..." git-subtree-dir: docs git-subtree-split: 988f7d5c2d7a1d40ec2c8ab961cb5a4e41b5bd4c
2020-03-09 19:19:32 +00:00
</ul>
```
If you want to list taxonomies inline, you will have to take care of optional plural endings in the title (if multiple taxonomies), as well as commas. Let's say we have a taxonomy "directors" such as `directors: [ "Joel Coen", "Ethan Coen" ]` in the TOML-format front matter.
To list such taxonomies, use the following:
### Example: Comma-delimit Tags in a Single Page Template
```go-html-template
{{ $taxo := "directors" }} <!-- Use the plural form here -->
{{ with .Param $taxo }}
<strong>Director{{ if gt (len .) 1 }}s{{ end }}:</strong>
{{ range $index, $director := . }}
{{- if gt $index 0 }}, {{ end -}}
{{ with $.Site.GetPage (printf "/%s/%s" $taxo $director) -}}
<a href="{{ .Permalink }}">{{ $director }}</a>
{{- end -}}
{{- end -}}
{{ end }}
```
Alternatively, you may use the [delimit template function][delimit] as a shortcut if the taxonomies should just be listed with a separator. See {{< gh 2143 >}} on GitHub for discussion.
## List Content with the Same Taxonomy Term
If you are using a taxonomy for something like a series of posts, you can list individual pages associated with the same taxonomy. This is also a quick and dirty method for showing related content:
### Example: Showing Content in Same Series
```go-html-template
<ul>
{{ range .Site.Taxonomies.series.golang }}
<li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></li>
{{ end }}
</ul>
```
## List All content in a Given taxonomy
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.
### Example: Grouping "Featured" Content
```go-html-template
<section id="menu">
<ul>
{{ range $key, $taxonomy := .Site.Taxonomies.featured }}
<li>{{ $key }}</li>
<ul>
{{ range $taxonomy.Pages }}
<li hugo-nav="{{ .RelPermalink}}"><a href="{{ .Permalink}}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
</ul>
</section>
```
## Render a Site's Taxonomies
If you wish to display the list of all keys for your site's taxonomy, you can retrieve them from the [`.Site` variable][sitevars] available on every page.
This may take the form of a tag cloud, a menu, or simply a list.
The following example displays all terms in a site's tags taxonomy:
### Example: List All Site Tags {#example-list-all-site-tags}
```go-html-template
<ul>
{{ range .Site.Taxonomies.tags }}
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
{{ end }}
</ul>
```
### Example: List All Taxonomies, Terms, and Assigned Content
This example will list all taxonomies and their terms, as well as all the content assigned to each of the terms.
{{< code file="layouts/partials/all-taxonomies.html" download="all-taxonomies.html" download="all-taxonomies.html" >}}
<section>
<ul id="all-taxonomies">
{{ range $taxonomy_term, $taxonomy := .Site.Taxonomies }}
{{ with $.Site.GetPage (printf "/%s" $taxonomy_term) }}
<li><a href="{{ .Permalink }}">{{ $taxonomy_term }}</a>
<ul>
{{ range $key, $value := $taxonomy }}
<li>{{ $key }}</li>
<ul>
{{ range $value.Pages }}
<li hugo-nav="{{ .RelPermalink}}">
<a href="{{ .Permalink}}">{{ .LinkTitle }}</a>
</li>
{{ end }}
</ul>
{{ end }}
</ul>
</li>
{{ end }}
{{ end }}
</ul>
</section>
{{< /code >}}
## `.Site.GetPage` for Taxonomies
Because taxonomies are lists, the [`.GetPage` function][getpage] can be used to get all the pages associated with a particular taxonomy term using a terse syntax. The following ranges over the full list of tags on your site and links to each of the individual taxonomy pages for each term without having to use the more fragile URL construction of the ["List All Site Tags" example above]({{< relref "#example-list-all-site-tags" >}}):
{{< code file="links-to-all-tags.html" >}}
{{ $taxo := "tags" }}
<ul class="{{ $taxo }}">
{{ with ($.Site.GetPage (printf "/%s" $taxo)) }}
{{ range .Pages }}
<li><a href="{{ .Permalink }}">{{ .Title}}</a></li>
{{ end }}
{{ end }}
</ul>
{{< /code >}}
<!-- TODO: ### `.Site.GetPage` Taxonomy List Example -->
<!-- TODO: ### `.Site.GetPage` Taxonomy Terms Example -->
[delimit]: /functions/delimit/
[getpage]: /functions/getpage/
[lists]: /templates/lists/
[renderlists]: /templates/lists/
[single page template]: /templates/single-page-templates/
[sitevars]: /variables/site/