$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)
Example
<ul>
<?php foreach($page->children()->sortBy('title', 'desc') as $subpage): ?>
<li>
<a href="<?= $subpage->url() ?>">
<?= html($subpage->title()) ?>
</a>
</li>
<?php endforeach ?>
</ul>
It's also possible to sort by more than one field like this:
<?php
$articles = page('blog')->children()->sortBy('date', 'desc', 'time', 'asc');
?>