2014-08-29 23:42:26 -04:00
|
|
|
---
|
2016-01-06 17:45:19 -05:00
|
|
|
lastmod: 2015-12-23
|
2014-08-29 23:42:26 -04: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 11:31:07 -05:00
|
|
|
.Get(term)
|
|
|
|
: Returns the WeightedPages for a term.
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.Count(term)
|
|
|
|
: The number of pieces of content assigned to this term.
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.Alphabetical
|
|
|
|
: Returns an OrderedTaxonomy (slice) ordered by Term.
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.ByCount
|
|
|
|
: Returns an OrderedTaxonomy (slice) ordered by number of entries.
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
## OrderedTaxonomy
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
Since Maps are unordered, an OrderedTaxonomy is a special structure that has a defined order.
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
```go
|
|
|
|
[]struct {
|
|
|
|
Name string
|
|
|
|
WeightedPages WeightedPages
|
|
|
|
}
|
|
|
|
```
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
Each element of the slice has:
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.Term
|
|
|
|
: The Term used.
|
2014-08-29 23:42:26 -04:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.WeightedPages
|
|
|
|
: A slice of Weighted Pages.
|
2015-01-19 13:44:14 -05:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.Count
|
|
|
|
: The number of pieces of content assigned to this term.
|
2015-01-19 13:44:14 -05:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.Pages
|
|
|
|
: All Pages assigned to this term. All [list methods](/templates/list/) are available to this.
|
2015-01-19 13:44:14 -05:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
## WeightedPages
|
2015-01-19 13:44:14 -05:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
WeightedPages is simply a slice of WeightedPage.
|
2015-01-19 13:44:14 -05:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
```go
|
|
|
|
type WeightedPages []WeightedPage
|
|
|
|
```
|
2015-01-19 13:44:14 -05:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.Count(term)
|
|
|
|
: The number of pieces of content assigned to this term.
|
2015-01-19 13:44:14 -05:00
|
|
|
|
2015-12-23 11:31:07 -05:00
|
|
|
.Pages
|
|
|
|
: Returns a slice of pages, which then can be ordered using any of the [list methods](/templates/list/).
|