-
Hello, I want to show on the article page, next to the title show which subcategory it belongs to, having previously created them: news (Main category)
I try this code near
I check this code
and it show Category not found. This article have two categories - news and articles. And if it possible to show only assigned subcategories. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
You need to use this: <ul>
{% for category in post.categories %}
<li>{{ category.name }}</li>
{% endfor %}
</ul> |
Beta Was this translation helpful? Give feedback.
-
Can't you just assign the subcategory and not its parent as the article categories ? |
Beta Was this translation helpful? Give feedback.
-
This is an option, but I then need to display 2 types of subcategories in one section. Now it looks like:
How make 2 categories in this? I try
and
It not working and show all in blog. |
Beta Was this translation helpful? Give feedback.
-
Oh, I see what you mean now. I guess you need to add more code in twig to only show leaves categories |
Beta Was this translation helpful? Give feedback.
-
Something like this maybe ? <ul>
{% for category in post.categories %}
{% if category.isLeaf() %}
<li>{{ category.name }}</li>
{% endif %}
{% endfor %}
</ul> |
Beta Was this translation helpful? Give feedback.
You need to use this: