$pages->sortBy($field, $direction = 'asc', $method = SORT_REGULAR)

Returns a sorted version of the collection

  • $field (string)
    The field from the content file
  • $direction (string)
    The sort direction: ascending (asc) or descending (desc)
  • $method (int)
    The sort flag, e.g. SORT_REGULAR, SORT_NUMERIC etc.
  • return ($pages)


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

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

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

Is something missing or incorrect? Edit this page on Github…