Skip to content

Kirby 4.2.0


$pages->sortBy(...$args = null): Kirby\Cms\Pages


Name Type Default
... $args mixed null

Return type


This method does not modify the existing $pages object but returns a new object with the changes applied. Learn more →

Parent class

Kirby\Cms\Pages inherited from Kirby\Toolkit\Collection


  <?php foreach($page->children()->sortBy('title', 'desc') as $subpage): ?>
    <a href="<?= $subpage->url() ?>">
      <?= $subpage->title()->html() ?>
  <?php endforeach ?>

It's also possible to sort by more than one field:

$articles = page('notes')->children()->sortBy('date', 'desc', 'time', 'asc');

For more complex sorting examples, check out our "Sorting" recipe