rasteiner / k3-pagesdisplay-section

K3 plugin: display any page list in a section. Any parent, many parents, filtered, don't care.
Other
45 stars 8 forks source link

sortBy possible? #4

Closed sbstnslg closed 3 years ago

sbstnslg commented 3 years ago

Im using your plugin to display featured items from 4 different pages with query: site.index.filterBy('Feature', '*=', 'true') but this is unsorted :-/

Any chance to order the list by date?

rasteiner commented 3 years ago

have you tried query: site.index.filterBy('Feature', '*=', 'true').sortBy('date', 'desc')? (change desc with asc if you want oldest first). I assume every page in your website that has a Feature field also has a date field?

If it doesn't work, you can always point to a collection, with query: kirby.collection('featured'). Then in site/collections/featured.php put something like this:

<?php

return function($site) {
  return $site->index()->filterBy('Feature', '*=', 'true')->sortBy('date', 'desc'); //or whatever you can do in PHP :)
};
sbstnslg commented 3 years ago

Oh that was too easy that I didn't figure it out myself - your first suggestion is the solution :-) Thx in advance!