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

Display pages with the same category

Started by Daimko 9 years ago · 4 replies · 1496 views
9 years ago

Hello,

I want to display the other pages with the same category as the current page. I added this code in blog_item.html.twig which displays all the pages right now :

TWIG
<ul class="liste-articles">
{% for p in page.parent.children if p != page %}
    <li>
        <a href="{{ p.url }}">{{ p.title }}</a>
    </li>
{% endfor %}
</ul>

Thank you in advance for your help !

9 years ago

Thank you,
I have read this page without finding a solution to my problem...
If anyone has an idea, I'm a taker !

9 years ago

@Daimko:
<ul class="liste-articles">
{% for p in page.parent.children if p != page %}
<li>
<a href="{{ p.url }}">{{ p.title }}</a>
</li>
{% endfor %}
</ul>

Hello,

Thank you for your help but I don't think I have been clear enough, sorry I'm French and I have trouble expressing myself correctly in English.

Simply put: All my articles are subpages of the home page that display them. At the end of each subpage, I want to display the other articles that have the same category as the current subpage. Currently, all subpages are displayed at the end of each article.

I hope I have been clear and thank you in advance for your help.

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 11 months ago
6 1200 11 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 964 1 year ago
Content & Markdown · by Jan L'Am, 2 years ago
4 843 2 years ago
Content & Markdown · by Leonardo, 2 years ago
3 765 2 years ago
Content & Markdown · by belthasar, 2 years ago
4 1180 2 years ago