Sorting by amount of included pages

Hey,
I build a portfolio website and I want to organize in the panel my projects-categories with included projects.

Panel Pages structure:

Work
projects-categories
projects-01
projects-02
projects-03
projects-04
projects-categories
projects-01
projects-02
projects-categories
projects-01

I want that the children in “Work” sort them by amount of children in the “projects-categories”.

Is that possible through (sort: … ) blueprint ?

Create a custom page method noOfChildren() and then use this method to sort by.

Custom method (in a plugin file):

page::$methods['noOfChildren'] = function($page) {
  return $page->children()->count();
};

In your work.yml

sort: noOfChildren desc

That way, you can basically sort by anything.

Got an error and I have no idea what that mean.

page::$methods[‘noOfChildren’] = function( page(‘discipline’) ) { return page(‘discipline’)->children()->index()->count(); };
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/…

Please use the code exactly as in my above post, don’t pass a particular page.