Show sites (cards) filtered by categories/tags

#1

Hi,

I use the theme “Quark Open Publishing”.

Now I would like to create an overview of certain pages. The layout should be like the overview in the blog (cards). But I want to filter the pages shown there.

For example:

Show all pages of the category “important” in the overview.

What is the easiest way to get there?

At the moment I’m thinking about using blog.html.twig and /partials/blog-item.html.twig as a template.

What would you do?

#2

make a new layout - e.g. important.html.twig, and filter that category in there like this:

{% for post in taxonomy.findTaxonomy({'category':'important'}).order('date','desc') %}
{{ post.date|date('d.m.Y') }} - <a href="{{ post.url }}">{{ post.title }}</a><br>
{% endfor %}

then use this template for your overview page.

1 Like
#3

Hi and thanks!

It was even easier.

copy blog.html.twig > important.html.twig

Edit: important.html.twig

Change:

{# display posts with 'featured' tag on current blog page - hibbittsdesign.org #}
                {% for child in taxonomy.findTaxonomy({'tag': "featured"}) %}

                   {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
            {% endfor %}

                {# display posts without 'featured' tag - hibbittsdesign.org #}
                {% for child in collection %}
                    {% if "featured" not in child.taxonomy['tag'] %}
                        {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
                    {% endif %}
                {% endfor %}

To:

{# display posts with 'important' category on current blog page - hibbittsdesign.org #}
                {% for child in taxonomy.findTaxonomy({'category': "important"}) %}
                    {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
                {% endfor %}

                {# display posts without 'important' category - hibbittsdesign.org #}
                {% for child in collection %}
                    {% if "important" not in child.taxonomy['category'] %}
                        {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
                    {% endif %}
                {% endfor %}