2013-12-20 18:11:49 -05:00
---
2014-05-29 18:42:05 -04:00
aliases:
- /indexes/ordering/
2016-01-06 17:45:19 -05:00
lastmod: 2015-12-23
2014-05-29 18:42:05 -04:00
date: 2013-07-01
linktitle: Ordering
2014-04-23 03:00:11 -04:00
menu:
main:
2014-05-29 18:42:05 -04:00
identifier: Ordering Taxonomies
parent: taxonomy
2014-10-25 10:13:06 -04:00
next: /taxonomies/methods
2014-05-29 18:42:05 -04:00
prev: /taxonomies/templates
title: Ordering Taxonomies
weight: 60
2015-05-22 14:46:09 -04:00
toc: true
2013-12-20 18:11:49 -05:00
---
Hugo provides the ability to both:
2015-01-29 14:34:56 -05:00
1. Order the way the keys for a taxonomy are displayed
2014-05-27 18:32:57 -04:00
2. Order the way taxonomyed content appears
2013-12-20 18:11:49 -05:00
2014-05-27 18:32:57 -04:00
## Ordering Taxonomies
Taxonomies can be ordered by either alphabetical key or by the number of content pieces assigned to that key.
2013-12-20 18:11:49 -05:00
2015-05-22 14:46:09 -04:00
### Order Alphabetically Example
2013-12-20 18:11:49 -05:00
2014-05-15 09:57:36 -04:00
< ul >
{{ $data := .Data }}
2014-05-27 18:32:57 -04:00
{{ range $key, $value := .Data.Taxonomy.Alphabetical }}
2016-05-14 00:35:16 -04:00
< li > < a href = "{{ .Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}" > {{ $value.Name }} < / a > {{ $value.Count }} < / li >
2014-05-15 09:57:36 -04:00
{{ end }}
< / ul >
2013-12-20 18:11:49 -05:00
2015-05-22 14:46:09 -04:00
### Order by Popularity Example
2013-12-20 18:11:49 -05:00
2014-05-15 09:57:36 -04:00
< ul >
{{ $data := .Data }}
2014-05-27 18:32:57 -04:00
{{ range $key, $value := .Data.Taxonomy.ByCount }}
2016-05-14 00:35:16 -04:00
< li > < a href = "{{ .Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}" > {{ $value.Name }} < / a > {{ $value.Count }} < / li >
2014-05-15 09:57:36 -04:00
{{ end }}
< / ul >
2013-12-20 18:11:49 -05:00
2015-11-04 18:33:03 -05:00
[See Also Taxonomy Lists ]({{< relref "templates/list.md" >}} )
2013-12-20 18:11:49 -05:00
2014-05-27 18:32:57 -04:00
## Ordering Content within Taxonomies
2013-12-20 18:11:49 -05:00
2014-05-27 18:32:57 -04:00
Hugo uses both **Date** and **Weight** to order content within taxonomies.
2013-12-20 18:11:49 -05:00
Each piece of content in Hugo can optionally be assigned a date.
2014-05-27 18:32:57 -04:00
It can also be assigned a weight for each taxonomy it is assigned to.
2013-12-20 18:11:49 -05:00
2014-05-27 18:32:57 -04:00
When iterating over content within taxonomies the default sort is first by weight then by date. This means that if the weights for two pieces of content are the same, than the more recent content will be displayed first. The default weight for any piece of content is 0.
2013-12-20 18:11:49 -05:00
### Assigning Weight
2014-05-27 18:32:57 -04:00
Content can be assigned weight for each taxonomy that it's assigned to.
2013-12-20 18:11:49 -05:00
2015-12-23 11:31:07 -05:00
```toml
+++
tags = [ "a", "b", "c" ]
tags_weight = 22
categories = ["d"]
title = "foo"
categories_weight = 44
+++
Front Matter with weighted tags and categories
```
2013-12-20 18:11:49 -05:00
2014-05-27 18:32:57 -04:00
The convention is `taxonomyname_weight` .
2013-12-20 18:11:49 -05:00
2014-05-27 18:32:57 -04:00
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.
2013-12-20 18:11:49 -05:00
It has also been assigned the weight of 44 when rendering the 'd' category.
2014-05-27 18:32:57 -04:00
With this the same piece of content can appear in different positions in different taxonomies.
2013-12-20 18:11:49 -05:00
2014-05-27 18:32:57 -04:00
Currently taxonomies only support the default ordering of content which is weight -> date.