mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
@@ -1,13 +0,0 @@
|
||||
---
|
||||
cascade:
|
||||
_build:
|
||||
list: never
|
||||
publishResources: false
|
||||
render: never
|
||||
---
|
||||
|
||||
<!--
|
||||
Files within this headless branch bundle are markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
|
||||
|
||||
Include the rendered content using the "include" shortcode.
|
||||
-->
|
@@ -1,68 +0,0 @@
|
||||
---
|
||||
# Do not remove front matter.
|
||||
---
|
||||
|
||||
Before we can use a `Taxonomy` method, we need to capture a `Taxonomy` object.
|
||||
|
||||
## Capture a taxonomy object
|
||||
|
||||
Consider this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[taxonomies]
|
||||
genre = 'genres'
|
||||
author = 'authors'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
And this content structure:
|
||||
|
||||
```text
|
||||
content/
|
||||
├── books/
|
||||
│ ├── and-then-there-were-none.md --> genres: suspense
|
||||
│ ├── death-on-the-nile.md --> genres: suspense
|
||||
│ └── jamaica-inn.md --> genres: suspense, romance
|
||||
│ └── pride-and-prejudice.md --> genres: romance
|
||||
└── _index.md
|
||||
```
|
||||
|
||||
To capture the "genres" taxonomy object from within any template, use the [`Taxonomies`] method on a `Site` object.
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomyObject := .Site.Taxonomies.genres }}
|
||||
```
|
||||
|
||||
To capture the "genres" taxonomy object when rendering its page with a taxonomy template, use the [`Terms`] method on the page's [`Data`] object:
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ $taxonomyObject := .Data.Terms }}
|
||||
{{< /code >}}
|
||||
|
||||
To inspect the data structure:
|
||||
|
||||
```go-html-template
|
||||
<pre>{{ jsonify (dict "indent" " ") $taxonomyObject }}</pre>
|
||||
```
|
||||
|
||||
Although the [`Alphabetical`] and [`ByCount`] methods provide a better data structure for ranging through the taxonomy, you can render the weighted pages by term directly from the `Taxonomy` object:
|
||||
|
||||
```go-html-template
|
||||
{{ range $term, $weightedPages := $taxonomyObject }}
|
||||
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a></h2>
|
||||
<ul>
|
||||
{{ range $weightedPages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
In the example above, the first anchor element is a link to the term page.
|
||||
|
||||
|
||||
[`Alphabetical`]: /methods/taxonomy/alphabetical
|
||||
[`ByCount`]: /methods/taxonomy/bycount
|
||||
|
||||
[`data`]: /methods/page/data
|
||||
[`terms`]: /methods/page/data/#in-a-taxonomy-template
|
||||
[`taxonomies`]: /methods/site/taxonomies
|
@@ -1,25 +0,0 @@
|
||||
---
|
||||
# Do not remove front matter.
|
||||
---
|
||||
|
||||
An ordered taxonomy is a slice, where each element is an object that contains the term and a slice of its weighted pages.
|
||||
|
||||
Each element of the slice provides these methods:
|
||||
|
||||
Count
|
||||
: (`int`) Returns the number of pages to which the term is assigned.
|
||||
|
||||
Page
|
||||
: (`page.Page`) Returns the term's `Page` object, useful for linking to the term page.
|
||||
|
||||
Pages
|
||||
: (`page.Pages`) Returns a `Pages` object containing the `Page` objects to which the term is assigned, sorted by [taxonomic weight]. To sort or group, use any of the [methods] available to the `Pages` object. For example, sort by the last modification date.
|
||||
|
||||
Term
|
||||
: (`string`) Returns the term name.
|
||||
|
||||
WeightedPages
|
||||
: (`page.WeightedPages`) Returns a slice of weighted pages to which the term is assigned, sorted by [taxonomic weight]. The `Pages` method above is more flexible, allowing you to sort and group.
|
||||
|
||||
[methods]: /methods/pages
|
||||
[taxonomic weight]: /getting-started/glossary/#taxonomic-weight
|
Reference in New Issue
Block a user