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

Page collection - target all posts but no pages

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

I want to put list of all blog posts in main directory of the website (not /blog). How can I tell Grav to list all the posts (but omit pages) in twig?

I added in front matter this but this will list also pages (as I target @root):

YAML
title: 'XXXXX'

sitemap:
    changefreq: monthly
    priority: 1.03

content:
    items:
        '@root'
    order:
        by: date
        dir: desc
    limit: 10
    pagination: true
feed: 
    description: 'XXXXX'
    limit: 10
10 years ago

If you have defined all your blog posts with some taxonomy, you can just use a collection that filters that taxonomy.

For example, I commonly set:

YAML
taxonomy:
  category: blog

In all blog pages. That way I can easily gather up all my blog posts whenever I need them by just retrieving items with that blog category - more info here: https://learn.getgrav.org/content/collections#taxonomy-collections

YAML

content:
   items:
      '@taxonomy.category': blog
---
10 years ago

@rhukster - Yeah but it would be more handy if I don't need to set each time for new blog post specific taxonomy and instead, Grav could automatically fetch only post type and not page type (based on template). So I could filter it like you can do it in twig by {% if page.template == 'post' %}

..so in front matter something along the way of:

YAML
content:
   items:
     post: true

Is there something existing I could reuse? Tried post: true and page.template: post but it doesn't work this way 😁

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1366 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago