Add newly published pages to the top of a sortable pages section

I have a sortable pages section and I need pages to be added to the top of when they are published. I thought is would work, but I get "Call to a member function isListed() on null"

'hooks' => [
        'page.changeStatus:after' => function ($page) {
            if (!$page->isListed()) {
                $page->sort(1);
            }
        }
    ]

Wrong variable, see page.changeStatus:after | Kirby CMS

cheers, it now works and changes the newly published page to have a sort order of 1. Is there a method to update all the other pages sort index otherwise they will all have the same sort order?

'hooks' => [
        'page.changeStatus:after' => function ($newPage,$oldPage) {
            if (!$oldPage->isListed()) {
                $newPage->changeSort(1);
            }
        }
    ]

Siblings are automatically resorted.

For me it just creates another folder in the number 1 slot:

Screenshot 2023-02-23 at 10.53.50

1 Like