$pages->sortBy()
Alias for Kirby\Toolkit\Collection::sort
$pages->sortBy($args = null): Collection
Parameters
Name | Type | Default | Description |
---|---|---|---|
$args |
null |
Return type
Collection
Example
<ul>
<?php foreach($page->children()->sortBy('title', 'desc') as $subpage): ?>
<li>
<a href="<?= $subpage->url() ?>">
<?= $subpage->title()->html() ?>
</a>
</li>
<?php endforeach ?>
</ul>
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
Inherited from
Kirby\Toolkit\Collection