Skip to content

Kirby 3.8.4

$pages->groupBy()

$pages->groupBy($args = null): Kirby\Toolkit\Collection

Parameters

Name Type Default
$args mixed null

Return type

Kirby\Toolkit\Collection

Exceptions

Type Description
Exception

Parent class

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

Example:

<?php
$years = page('projects')->children()->groupBy('year');
foreach($years as $year => $items): ?>
    <h2><?= $year ?></h2>
    <ul>
      <?php foreach($items as $item) : ?>
      <li><?= $item->title() ?></li>
      <?php endforeach; ?>
    </ul>
<?php endforeach ?>

More information

Grouping collections