Taxonomies

Taxonomies

Taxonomies group posts with terms, such as categories, tags, or custom project types.

Show Categories#

Use a paired taxonomy tag to loop the terms on the current post:

phpresources/views/single.php
{{ categories }}  <a href="{{ url }}">{{ title }}</a>{{ /categories }}

Inside the loop, {{ title }} is the term name and {{ url }} is the term archive URL.

Show Tags#

Tags use the same shape:

phpresources/views/single.php
{{ tags }}  <a href="{{ url }}">{{ title }}</a>{{ /tags }}

categories maps to the WordPress category taxonomy.

tags maps to the WordPress post_tag taxonomy.

Use Custom Taxonomies#

For custom taxonomies, use the taxonomy name:

phpresources/views/single-project.php
{{ project_types }}  <a href="{{ url }}">{{ title }}</a>  <span>{{ slug }}</span>{{ /project_types }}

Common term values are {{ title }}, {{ name }}, {{ slug }}, {{ url }}, and {{ count }}.

Inside A Query#

Taxonomy loops use the current post, so they also work inside query loops:

phpresources/views/front-page.php
{{ query:posts limit="3" }}  <article>    <h2><a href="{{ url }}">{{ title }}</a></h2>    {{ categories }}      <a href="{{ url }}">{{ title }}</a>    {{ /categories }}  </article>{{ /query:posts }}

Inside query:posts, the categories belong to each post in the query.

Filter By Taxonomy#

Use taxonomy:{taxonomy} to query posts by term slug:

php
{{ query:posts taxonomy:category="news" limit="6" }}  <h2><a href="{{ url }}">{{ title }}</a></h2>{{ /query:posts }}

Use pipes when more than one term can match:

php
{{ query:posts taxonomy:post_tag="bread|recipe" limit="6" }}  <h2><a href="{{ url }}">{{ title }}</a></h2>{{ /query:posts }}

For the full filtering syntax, see Query Loop Filtering.