2 min read

Views grouping by letters in Drupal 7

Sometimes, for better usability, you need to create a menu or list of content grouped by the first letter of the title. To achieve this, you will need the Views_php module.

After installing and enabling the module, add a field of type Global: PHP in Views and exclude it from display. The content for the new field’s Value Code:

$label = mb_substr($row->name, 0, 1);
if (is_numeric($label)) {
    $label = '0 - 9';
}
return mb_strtoupper($label);

Views grouping by letters in Drupal 7

After this, configure the format settings to group by the newly created PHP field:

Views grouping by letters in Drupal 7

As a result, you will get a menu like this:

Views grouping by letters in Drupal 7