Pages: option sortBy

Hi,

I use the option “sortBy” to sort pages in a panel section. The “sortBy” option works to sort the pages but the prev/next button seems not to consider the “sortBy”.

I made a test on the starter-kit. I added a “questionId” in “Notes” txt files and sort the notes pages on this “questionId”.

notes.yml

type: pages
headline: Notes
parent: kirby.page("notes")
info: "{{ page.questionId }}"
template: note
empty: No notes yet
sortBy: questionId asc

You can download the code here:

I know more situations in Kirby 3 panel, where the prev/next buttons do not work like I need, e.g. if they have different blueprints.

Looking at the source code, sorting is ignored

        'next' => function (Page $page) {
            return $page
                ->nextAll()
                ->filterBy('intendedTemplate', $page->intendedTemplate())
                ->filterBy('status', $page->status())
                ->filterBy('isReadable', true)
                ->first();
        }
   public function nextAll()
    {
        return $this->siblingsCollection()->slice($this->indexOf() + 1);
    }
 protected function siblingsCollection()
    {
        if ($this->isDraft() === true) {
            return $this->parentModel()->drafts();
        } else {
            return $this->parentModel()->children();
        }
    }

You could create a custom section…

:thinking: You mean as we do with a page models?

Could you show me how to start, I’m not sure to understand

No, I mean a custom pages section plugin: https://getkirby.com/docs/reference/plugins/extensions/sections

You can reuse the existing pages section, and add sorting of pages to it. Here is an example plugin that extends the pages section: https://github.com/rasteiner/k3-pagesdisplay-section

Of course, you can additionally create a feature request in the ideas repo.

Amazing, another new Kirby trick I didn’t know :slight_smile:
I will take a look at it later …

Thanks Sonja