Get -recursively- all pages

I have the following structure:


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)

There is several ways of solving this problem.
Basically, you have to adjust your collection in order to get these pages:

    - '@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

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'}}) %}