Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Show child items with certain taxonomy

Started by Muut Archive 10 years ago · 1 replies · 416 views
10 years ago

Hello! I'm building my first Grav project, which is a magazine-style blog, essentially. I'd like to populate different divs on my "index" page with "blog" items of different taxonomies (so all the items tagged "HCI" would show up in one area (under a hard-coded heading) and those tagged "Data Science" would show up in another. My instincts tell me to use an if statement in here somewhere:

TWIG
{% for child in collection %}
  {% include 'partials/blog_item.html.twig' with {'page':child, 'truncate':true} %}
{% endfor %}

like with this pseudo code, repeated for each section:

TWIG
{% for child in collection %}
   ### if child has taxonomy "category1" ###
  {% include 'partials/blog_item.html.twig' with {'page':child, 'truncate':true} %}
{% endfor %}

Loving Grav so far. Would appreciate any tips. Thanks!

10 years ago

It's all described in the Taxonomy Guide.

Sample code:

TWIG
<h2>Kevin Smith's Posts</h2>
<ul>
{% for post in taxonomy.findTaxonomy({'tag':'a-tag-value'}) %}
    <li>{{ post.title }}</li>
{% endfor %}
<ul>

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2957 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago