2014-08-30 03:42:26 +00:00
|
|
|
---
|
2016-01-06 22:45:19 +00:00
|
|
|
lastmod: 2015-12-23
|
2014-08-30 03:42:26 +00:00
|
|
|
date: 2014-05-26
|
|
|
|
linktitle: Structure & Methods
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
parent: taxonomy
|
|
|
|
next: /extras/aliases
|
|
|
|
prev: /taxonomies/ordering
|
|
|
|
title: Using Taxonomies
|
|
|
|
weight: 75
|
|
|
|
---
|
|
|
|
|
|
|
|
Hugo makes a set of values and methods available on the various Taxonomy structures.
|
|
|
|
|
|
|
|
## Taxonomy Methods
|
|
|
|
|
|
|
|
A Taxonomy is a `map[string]WeightedPages`.
|
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Get(term)
|
|
|
|
: Returns the WeightedPages for a term.
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Count(term)
|
|
|
|
: The number of pieces of content assigned to this term.
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Alphabetical
|
|
|
|
: Returns an OrderedTaxonomy (slice) ordered by Term.
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.ByCount
|
|
|
|
: Returns an OrderedTaxonomy (slice) ordered by number of entries.
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
## OrderedTaxonomy
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
Since Maps are unordered, an OrderedTaxonomy is a special structure that has a defined order.
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
```go
|
|
|
|
[]struct {
|
|
|
|
Name string
|
|
|
|
WeightedPages WeightedPages
|
|
|
|
}
|
|
|
|
```
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
Each element of the slice has:
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Term
|
|
|
|
: The Term used.
|
2014-08-30 03:42:26 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.WeightedPages
|
|
|
|
: A slice of Weighted Pages.
|
2015-01-19 18:44:14 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Count
|
|
|
|
: The number of pieces of content assigned to this term.
|
2015-01-19 18:44:14 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Pages
|
|
|
|
: All Pages assigned to this term. All [list methods](/templates/list/) are available to this.
|
2015-01-19 18:44:14 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
## WeightedPages
|
2015-01-19 18:44:14 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
WeightedPages is simply a slice of WeightedPage.
|
2015-01-19 18:44:14 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
```go
|
|
|
|
type WeightedPages []WeightedPage
|
|
|
|
```
|
2015-01-19 18:44:14 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Count(term)
|
|
|
|
: The number of pieces of content assigned to this term.
|
2015-01-19 18:44:14 +00:00
|
|
|
|
2015-12-23 16:31:07 +00:00
|
|
|
.Pages
|
|
|
|
: Returns a slice of pages, which then can be ordered using any of the [list methods](/templates/list/).
|