$pages->groupBy($field, $caseInsensitive = true)

Groups $page objects in the collection by any field and returns them in a new collection

  • $field (string)
    A field name
  • $caseInsensitive (boolean)
    Whether grouping by field should be case sensitive or not
  • return ($pages)

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 ?>