Learn

Taxonomies

Breaking your content into logical groups.

A taxonomy is a way of grouping your content together into logical bits. You can define as many taxonomies as you’d like within your settings.yaml file, like so:

taxonomies: [ categories, tags ]

This above example (which is what Statamic comes with by default) will let Statamic know that you’ll be using categories and tags fields as taxonomies in your content files.

Adding tags to a piece of content is a simple YAML list, like so:

---
title: My Blog Post
tags: [ bears, whips, adventure ]
---
My adventures in the woods…

Listing Used Taxonomies

Let’s say that you want to list out all of the tags used in your blog. You can use the taxonomy tag to display a list of those used.

{{ taxonomy:listing folder="blog" type="tags" }}
  {{ if first }}
     <ul>
  {{ endif }}

  <li>
     <a href="{{ url }}">{{ title }}</a>
  </li>

  {{ if last }}
     </ul>
  {{ endif }}
{{ /taxonomy:listing }}

You can order your list results too.

Showing Entries in a Taxonomy

Taxonomies can also be displayed with their own special template. By default, a taxonomy listing will use the taxonomies.html template, but you can override the template for each type of taxonomy by using its name. For example, if you create a tags.html template, that will be used when displaying listings based upon tags.

Within your taxonomy template (whether you’re using the default one, or the named one), you’ll want to display a list of entries with the taxonomy parameter set to true. This will dynamically find the appropriate taxonomy from the current URL doing the hard work for you.

This article was last updated on September 13th, 2016. Find an error? Please let us know!