lpa Posted April 21, 2022 Posted April 21, 2022 How could I define that the subfolders of a page are shown first and the children of the page then in the admin page tree? Now the children are shown first and if there are many pages inside a folder, the subfolders are shown on the last page.
BillH Posted April 21, 2022 Posted April 21, 2022 The way I've done things like this is to create a text field, use a hook to add a sort code to that field, then set each relevant parent template to sort its children using that field. The sort code would be whatever you'd normally sort by, but with a prefix that depends on whether the page has children or not. So, I'd use something like the following (not tested) in ready.php, here assuming you'd basically sort on title: $this->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments[0]; if(in_array($page->template, array('template1', 'template2', 'template3'))) { $page->of(false); if($page->numChildren() > 0) { $sortcode = "A-" . $page->title; ) else { $sortcode = "B-" . $page->title; } $page->set('sortcode', $sortcode); } }); Of course, you could use a hook in a module instead. And you can use the same basic technique to get just about any kind of sort order you want. 3
lpa Posted April 22, 2022 Author Posted April 22, 2022 Thanks! Seems to be too complicated for my needs. How about a simple hook for the sorting phase of the admin tree?
BillH Posted April 22, 2022 Posted April 22, 2022 I haven't tried, but you may be able to do it by hooking on ProcessPageList::find, as discussed here: Note that the pages would have to be loaded and the sort codes calculated each time the page tree was displayed, so I think the approach I have suggested would be more efficient – something that is discussed in the thread too.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now