Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Show child items with certain taxonomy

Started by Muut Archive 11 years ago · 1 replies · 509 views
11 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!

11 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 2607 9 years ago
Archive · by Muut Archive, 9 years ago
2 1714 9 years ago
Archive · by Muut Archive, 9 years ago
2 5009 9 years ago
Archive · by Muut Archive, 9 years ago
1 3838 9 years ago
Archive · by Muut Archive, 9 years ago
3 1819 9 years ago