Usk70
October 3, 2017, 10:23am
1
I have the following structure:
/blog
/area1
/blog_entry1
blog.md
/blog_entry2
blog.md
/blog_entry3
blog.md
/area2
/blog_entry4
blog.md
/area3
/blog_entry5
blog.md
/blog_entry6
blog.md
I have seen this recipe in twig:
Get last 5 post entries
But as far as I have tried, it does not work recursively.
Is there any option to recursively get the last 5 post entries of all .md files child of /blog ?
(which in this case would be blog_entry1 to blog_entry6)
paul
October 3, 2017, 12:59pm
2
There is several ways of solving this problem.
Basically, you have to adjust your collection in order to get these pages:
content:
items:
- '@page.children' : /area1
- '@page.children' : /area2
- '@page.children' : /area3
limit: 5
Then you just have to write:
{% for item in page.collection %}
{{item.title }}
{% endfor %}
Alternatively you could write:
{% for area in page.find('/blog').children %}
{% for article in area.children %}
{{ article.title }}
{% endfor %}
{% endfor %}
Not tested, but it might work
1 Like
OleVik
October 3, 2017, 3:05pm
3
Also, there’s a recipe for recursively iterating through pages and media. You’d have to pass the resulting array back through Twig, though.
1 Like
You could use descendants instead of children.
{% for item in page.collection({'items': '@self.descendants','order': {'by': 'date','dir': 'desc'}}) %}
2 Likes