Sort an array by Month

If you have a standard Kirby collection, you can use group() with a callback, see the documentation example. Instead of using the month name to group by, use the month number. Then use a months array to get the corresponding month name.

As I said, there is an example somewhere, were Today, Future etc. should have been ordered. You just have to find it…

Think this was it: Custom Grouping Order

The problem here is not the grouping but the sort order, I don’t see how differentwould solve this issue.

<?php 

// group items by month
$groupedItems = $page->children()->visible()->group(function($p){
  return $p->date('n'); // group by numeric representation of a month, without leading zeros
});

Then in your template:

$months = [1 => 'January' ,  2 =>  'February',  3 => 'March', '...'];
foreach ($groupedItems as $monthNumber => $monthList): ?>
  <h2><?= $months[$monthNumber] ?></h2>
  <ul>
    <?php foreach($monthList as $article): ?>
      <li><a href="<?= $article->url() ?>"><?= $article->title() ?></a></li>
    <?php endforeach ?>
  </ul>
<?php endforeach ?>