Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Getting all pages + subpages

Started by Muut Archive 10 years ago · 2 replies · 476 views
10 years ago

How would I go around getting all pages and subpages so I could make like a latest posts list but with all pages and subpages ...

10 years ago

Have a look at the Pages Object, it allows access to all Grav pages and you can iterate over them to create the desired output.

Get the top-level pages for a simple menu (from the documentation):

TWIG

<ul class="navigation">
    {% for page in pages.children %}
        {% if page.visible %}
            <li><a href="{{ page.url }}">{{ page.menu }}</a></li>
        {% endif %}
    {% endfor %}
</ul>
---
10 years ago

Added collection to the pages header

YAML
content:
    items: '@root.descendants'

and then added this to my template file

TWIG

<ul>
{% for post in page.collection.order('date', 'desc').slice(0, 5) %}
    <li class="recent-posts">
        <strong><a href="{{ post.url }}">{{ post.title }}</a></strong>
        <p>{{post.date|date}}</p>
    </li>
{% endfor %}
</ul>
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1355 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4065 9 years ago
Archive · by Muut Archive, 9 years ago
1 2953 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago