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