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

Custom order for a loop

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

I'm listing all the pages (from different folders) belonging to category "featured", and I'd like to order them by a custom value. At the moment they're being ordered by date:

TWIG
{% for p in taxonomy.findTaxonomy({'category':'featured'}).order('date','desc') %} 
    {{ p.title }}
{% endfor %}

However I want to add an "order" field in the page header

YAML
- - -
// for the first page to show
title: Just a page
order: 1 
- - -
- - -
// for the second page to show
title: Not just a page
order: 2
- - -

What I want is something like .order('p.header.order','asc')

Is there any way to do this?

10 years ago

It should be something like: .order('header.order', 'desc')

10 years ago

Whoops, that was simple, works perfectly. Thanks for the help!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2957 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago