Hi all,
I'm searching to create an alphabetical index of all my nodes of a specific content type using views. Anyway, all I can do with views is order all my nodes based on their title, but I also need to put a separator between each new starting letter. Something like this:

- August
- Auto

- Belgium
- Bed
- Bulgary

- Case study
- Citron

How can I get a result like that?

Thank you!


samchok’s picture

The only idea I have is to create 26 views (one for every letter of the alphabet) and display each of those views in the same page.
But it seems to me too long and complicated!

WorldFallz’s picture

An idea I've been tossing around for this, is to try to use views_customfield to create a field that consists of the first letter of the title (using the substr php function), and then using that field to group the view style. I just haven't had a chance to try it yet. Otherwise, it's probably a matter of a custom view template.

samchok’s picture

Thank you very much!
Following your suggestion (grouping by customfield) did the trick.

WorldFallz’s picture

awesome-- thanks for posting back, at least now we know it works. ;-)

aaroninaustin’s picture

I am trying to do this same thing. I have created the custom field and grouping works fine, but how do you display each of the grouping letters?

Sourcery’s picture


Perhaps you could assist me by telling me how you did the custom field?

Since I havent gotten that far in this I dont know the exact answer to your question... Try this:

Use the Style: Unformatted, press the cogwheel, and choose groupfield: and choose your custom field as groupfiled.

Sourcery’s picture

Hello again....

This was SO much simpler than integrating a lot of PHP code et al.

What you do is you add another field node title (so you have TWO node title in fields). This field, you shirten down to length 1. You also exclude from view.

Then you choose style: unformatted, and then choose the second node title as the group field.

E Voila! :) Simple and beautiful list from A-Z.

Hope this helps everyone looking for this function.


sunchaser’s picture

@Sourcery : well done !
used your technique and worked like a charm.

yul63’s picture

Very elegant

aaroninaustin’s picture

First, sorry I fell off this thread, for the sake of completeness, I'm back to clear up my vague comment/question. I really like your method, creating a title with a length of one, brilliant!

My situation ended up being a little weird, as in some departments in my company seem to have funny ideas about alphabetical ordering, so I needed a way to allow them to change their alphabetizing letter.

I created a CCK field that is auto-filled with the first letter of the title of the node, but can be changed if it needs to appear somewhere else in the list... Think 'School of Education' appearing under the E instead of S... anyway.

Other than that I used the same method your describing and it worked very well. :)

Fidelix’s picture

Unfortunately, this method will not work for grouping all number-starting titles under one page.

I'll try using views_customfield for this...

nuez’s picture

It doesn't seem to work for me in D7.
When grouping with the trimmed 'term field' the letter appears on top of every term entry. I think because it only trims the 'view' but not the actual value of the term field. Although the letter 'A' repeats itself, the value behind it is each time different, so it appears each time on top of each individual taxonomy entry.

My solution is adding a 'category' selection field to the taxonomy, as is posible in D7, and use it as a grouping field. letter. You can use letters as grouping field or other categories.

Freelance Drupal Professional @ Nuez Web

WorldFallz’s picture

I got it working without an additional field no problem. You need to add the term field 2 times-- once excluded from display and trimmed to one character (use this for the grouping field) and once to actually display the term itself.

dougthelegoman’s picture

Maybe this screencast will help: http://vimeo.com/21052075
for future ref.

bradspry’s picture

Thank you so much!

jd-dupe’s picture

Really :)?
When you're editing view:

  1. Prepare fields
    • in fields add new one field "The content title"
      • Uncheck "Create a Lable"
      • Check "Exclude from display"
      • in "REWRITE RESULTS"
        • Trim this field to a maximum length
          • Set "Maximum length" to 1
          • Uncheck "Add an ellipsis"
          • Uncheck "Trim only on a word boundary"
  2. Grouping
    • Change output format to "Grid" or "Table"
    • Configure output format and select "Grouping field Nr.1" your last added field
Fidelix’s picture

Nice. Unfortunately this method does not handle grouping of numbers/special characters.

Sumeet.Pareek’s picture

Thanks @jd this just did the trick for me for what I was trying to do on a listings page.

PieterDC’s picture

Thanks jd. It worked (for me too).

Sebastian Bańdo’s picture

This is just what I was looking for, thanks!

bronzehedwick’s picture

This is a great solution, unfortunately it doesn't account for casing of terms. For example, if there were the nodes

  • apple
  • Ape
  • Alamo

the output would be


  • apple


  • Ape
  • Alamo

Does anyone have any suggestions on how to solve this within views, or does this have to be solved in code?

bronzehedwick’s picture

The fix I found was to use the termcase module http://drupal.org/project/termcase/
I would have liked to have found something that didn't require an extra module, but this works.