A
A
an_tropa2021-06-03 05:53:18
Twig
an_tropa, 2021-06-03 05:53:18

How to display on the category page a list of subcategories and posts corresponding to these categories?

Guys, I ask for help.
On the site, I created the main category and subcategories:
60b840dade70c950356509.png

I need the subcategories and posts corresponding to these categories to be displayed on the page (as in the first screenshot).

I'm trying to make it look like this:

{% for post in blogPosts.posts %}
{% for category in post.categories %}
    {{ category.name }}
{% endfor %}
    <h2>{{ post.title }}</h2>
{% endfor %}

and it turns out not quite what you need, all posts from all categories are displayed, and the name of the category is assigned to them, i.e. the name of the category constantly appears above the post from that category.
60b8427d98e6e411828506.png

And I need to display only posts of a certain category, and in the sequence:
Category
name1 -post from category 1
-post from category 1
Category
name2 -post from category 2
-post from category 2


How can I make such a filter in Twig? ask for help from experienced fighters

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question