Sub-page ordering in the panel

panelfield
panel
#1

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?

0 Likes

#2

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

0 Likes

#3

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?

0 Likes

#4

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

#5

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

0 Likes

#6

You are welcome :slight_smile:

0 Likes

#7

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

0 Likes

#8

Yes, this has changed somewhat in Kirby 3:

1 Like