Sub-page ordering in the panel

For a blog page I’m building I managed to change the sort order to date (custom field). So now it’s set to date desc. This works as expected towards the frontend but in the panel, sub-pages are still ordered ascending instead of descending. For now that’s ok but once there are a lot of sub-pages (e.g. posts), the last post will always be on the bottom and that might become inconvenient. Is there a way to make the admin listen to the sort direction as defined in the blueprint?

Pls. see the docs: https://getkirby.com/docs/panel/blueprints/subpages-settings#sorting-of-subpages

Yes, that’s exactly what I have done. But I didn’t judge it right. In fact the panel’s sorting is right but the theme is doing it wrong.

So I was wondering, when I call $page->children(), are they returned in the sort order as configured in the blueprint? Or do I have to define the sort order in the template again?

In the blueprint, you only define how the subpages are displayed in the panel. To sort your pages on the frontend, you either define the sort order in your controller or your template, using sortBy():

<?php
$articles = $page->children()->visible()->sortBy('date', 'desc');
1 Like

Yes, that’s exactly what I did now. Thanks for your super swift replies!

You are welcome :slight_smile:

this link doesn’t work, is there different document now for kirby 3?

Yes, this has changed somewhat in Kirby 3:

1 Like

This is only sort of related, but I’ve found a bit of info about this topic so I’m replying here.

Q: I’m trying to output subpages but only ones that use a certain page template. Is it possible to restrict the pages that are returned in a loop in the page template, based on which template type is used for the current page’s subpages?

For example, some subpages could be testimonies, some could be reviews, and I only want the reviews to show in the loop.

Ideas? Here is the code I’m tinkering with:

<?php $reviews = $page->children()->listed()->shuffle() ?>
<?php foreach ($reviews as $item): ?>

What is your Kirby version?

In Kirby 3 you can filter by template like this:

<?php $reviews = $page->children()->listed()->template('sometemplate')->shuffle() ?>

Kirby 2

<?php $reviews = $page->children()->listed()->filterBy('template', 'sometemplate')->shuffle() ?>

Since you are using listed it’s likely Kirby 3, but you are posting in Kirby 2 context.

1 Like

Ah, perfect. Thanks. Running the latest public release. Yep, I was using K2 filterBy instead. :frowning:
Goops, I should repost this or delete my comments here.

As far as the panel goes, I’ve figured out how to restrict an additional page list to only list pages that use a certain template, but what about listing the opposite: every template except for ‘review’ templates?

Unfortunately, that’s not possible yet, so you have to explicitely enumerate every single allowed template, unless you create a custom section.

1 Like

Thanks! Not a problem. Very edge case.

These responses can be deleted. Thanks!