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

Loop through recents posts in all categories

Started by Muut Archive 11 years ago · 2 replies · 345 views
11 years ago

I've set up my site that the url format is like /categorie/posttitle (post.md looks like taxonomy: category: cat1).

For an index page I'd like to loop through the latest posts in ALL categories.

While I'm able to loop throught recent posts for a specific category

TWIG
<ul>
{% for post in page.find('/cat1').children.order('date', 'desc').slice(0, 10) %}
  <li>{{ post.title }}</li>
{% endfor %}
</ul>

(which works perfectly and returns the most recent posts for category 1) I'm stuck on doing it sidewide for most recent posts in all categories (/cat1, /cat2, /cat3).

I've tried page.find('/') or pages.children but no success.

Has anyone an idea?

11 years ago

rather than find a page by path, how about using a taxonomy? Ie, you can give every page a category taxonomy of post, and then use:

TWIG
{% for post in taxonomy.findTaxonomy({'category':'post'}).children.order('date', 'desc').slice(0, 10) %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago