Group articles by the first character of their title/name

I have a larger number of articles which are named after persons (e.g., Smith John, Sinatra Frank, Brando Marlin - just example names) and would like to make an overview page on which all names are listed (this is easy and not a problem). However I would like to group them by the first letter of their surname (title of article), so that I end up with a list as follows:

A

  • Armstrong, Mary
  • Ardvark, Brian
  • Antville, John

B

  • Burgundy, Frank
  • Boom, Johnny

Z

  • Zimbardo, Brian

How would I best go about this? Any idea much appreciated.

Hey Tina, you can use the group() function for this: https://getkirby.com/docs/reference/objects/pages/group

$groups = $page->children()->sortBy('title', 'asc')->group(function($item) {
  return Str::substr($item->title()->value(), 0, 1);
});
1 Like

Cool, thanks Sonja, I’ll give that a try :slight_smile: