$collection->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><?php echo $year ?></h2>
    <ul>
      <?php foreach($items as $item) : ?>
      <li><?php echo $item->title() ?></li>
      <?php endforeach; ?>
    </ul>
<?php endforeach ?>