Profile picture for user admin
Daniel Sipos
14 Nov 2012

Have you ever wondered what to do if a client asks you to add consecutive numbering before each node title in a View? You try to explain him ‘hang on, it’s not so simple because it is not a static page’ to which you get so often an answer like ‘of course it is, how hard could it be?

  1. Node title
  2. Another node title
  3. Another node title.
  4. etc node title

Well, it is definitely not hard in Drupal 7, but perhaps not so obvious. You probably know already how to add a simple result summary in your View to display the total number of rows. [Side lesson]: just add the Global: Result Summary field to the View footer or header and in there you can find the @total variable (among others) that displays the total number of rows.

Not really helpful in our case though. But there is something else that is similar and perfect for achieving this simple numbering. You can do the following:

Once you added all the fields you want to your View, exclude the title from displaying in anticipation of some field output rewriting. Now, if the View should contain only node titles, just add another field of the type: Global: View result counter. In its configuration, go under Rewrite results and check the box Rewrite the output of this field.

Then add into the box the following: [counter]. [title]

Save and test your View. This will output a single field per row that combines the title and the counter result (number) for each row in the format of [number][dot][title]. Pretty cool a?

Now, if you have more fields as your View is more complex, you can exclude them all from display except for the last one that you can rewrite in a custom way, or you can exclude only the title and you move the counter field right after it and rewrite the counter like I showed you in the example.

Hope this helps.

Profile picture for user admin

Daniel Sipos

CEO @ Web Omelette

Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.

Contact us

Comments

Giovanni Méndez Marín 02 Dec 2015 08:01

About hierarchy book

Hi Danny, thanks for this post.

Do you know how to create a Hierarchy headings, something like

  1. A
    1.1. B
    1.1.1. C
    1.1.2. D
  2. E

I am trying but i don't know

Dejavu 30 Mar 2016 01:05

Briliant

Can't believe i had to fight 15 minutes for this!!Thank you your for your post

Add new comment