Alphabetical Sorting of Drupal Nodes Using Views

tutuploadsmedia_1290010356863.png

This tutorial is designed to do two things:

  1. Show you how to sort Drupal nodes alphabetically
  2. Introduce you to the Views module

Views is, without question, the most important Drupal module that is not in the core. It allows you to use a graphical interface to sort and organize all your nodes. It a powerful but also complex module and it can take a lot of time to learn all its features. This tutorial will only help you get your feet wet.

This particular tutorial was inspired by a site member who had the contact details of many employees stored as nodes. They wanted to make an alphabetical directory of all the staff members.

Install Views

tutuploadsmedia_1290010356863.png

Download and install the Views module from the Drupal site: http://drupal.org/project/views

I’m also going to use the Devel module for this: http://drupal.org/project/devel. That has a “Generate Items” option that will allow me to create lots of dummy content to test my alphabetical directory.

Access Views

tutuploadsmedia_1290010719941.png

To access the Views module, go to Administer >> Site building >> Views

tutuploadsmedia_1290010801485.png

On the first Views screen you’ll see a list of sample views waiting to be activated. These include:

  • Archive: “Display a list of months that link to content for that month. “
  • Recent Comments: “Contains a block and a page to list recent comments”
  • Glossary: “A list of all content, by letter. “

Not surprisingly, Glossary is the one we want so click “Enable” next to it.

tutuploadsmedia_1290010861118.png

In order to see what this view will look like, click on the word “glosssary” next to Path:

tutuploadsmedia_1290010910397.png

You’ll see an alphabetical directory of nodes, listed according to their first letter:

tutuploadsmedia_1290010956201.png

Editing the View

tutuploadsmedia_1290010990439.png

In order to adapt this view to our needs, we’ll need to change some aspects of it. To do that, hit the back button in your browser and click on “Edit” next to the glossary entry. You’ll be taken to the main editing page for the Views module. This is where you can make any and all changes to your view:

tutuploadsmedia_1290011049567.png

Modifying the View’s Fields

tutuploadsmedia_1290011064292.png

We’re not going to explain all aspects of the views module in this short tutorial, but we will dive into some aspects of how it works.

For example, you will have noticed the view had three items from each node: the Title, the Author and the date of the Last update. For a directory of staff members, we don’t need those last two items, or as Drupal refers to them “fields”.

Here’s how to remove them:

tutuploadsmedia_1290011089966.png

Click on “User: Name Author”

tutuploadsmedia_1290011127688.png

Scroll all the way to the bottom of the page and click “Remove”.

The repeat the process for “Node: Last Updated” and when you’re done the Fields area should look like the screenshot below:

tutuploadsmedia_1290012946892.png

Filtering Out the Nodes in the View

tutuploadsmedia_1290012971811.png

One other step we’ll need to take is filtering our nodes so that only the Contact nodes are shown in the view. It won’t be a very good directory of staff members if pages, stories and other node types are included. We can do that via the “Filters” area. To get started, click on the plus sign.

tutuploadsmedia_1290011886559.png

You can filter by many different methods, but we’re going to choose the filter by Node type.

Use the dropdown menu to choose “Node” and quickly get to all the node-related filters. Then check “Node: Type” and click “Add”.

tutuploadsmedia_1290011945365.png

On the next screen, choose the nodes you’d like to appear on this view and then click “Update default display”. The final result should look like the screen below.

tutuploadsmedia_1290013635830.png

Now that you’ve made those changes, finish off by clicking “Save” at the bottom of the page.

tutuploadsmedia_1290012040236.png

That should be the final step

The End Result

tutuploadsmedia_1290012087522.png

This will be the end result of your work. All of your Contact nodes will be sorted in an alphabetical directory.

Hopefully it has also been a introduction to the Views module, one you’ll be using much more as you progress with Drupal.

{loadposition drupalnewsletter}

Author

  • Robbie Adair

    Robbie started her career in corporate training until starting her own custom training and media company almost seventeen years ago. In 2010, she began doing classroom training for OSTraining while running Media A-Team. She is often presenting about various tech topics such as Joomla, Fabrik, Web Development, Social Media, and Augmented Reality. She loves seeing that "ah-ha" moment in peoples eyes in her sessions and workshops. She lives in Houston, Texas, but enjoys all the travel for client work and speaking gigs.

0 0 votes
Article Rating
Subscribe
Notify of
6 Comments
Oldest
Newest
Inline Feedbacks
View all comments
ricco
ricco
13 years ago

Hi Steve, i tried this tutorial and it worked like a charm. i was wondering if i could use this to make the front page(story/anouncments) to look like a recent comments block instead, so i can make more room for other content(photos).

Steve Burge
Steve Burge
13 years ago
Reply to  ricco

Hi Ricco – yes, you can certainly do that with Views. in addition to Glossary, Views actually ships with a recent comments sample views.

astro
astro
12 years ago

Hi, very easy and nice working. However, how can I add a “All” options if I want by default having displayed all content

ibrahim
ibrahim
11 years ago

How display by default all the letters of the alphabet?

justluvgod
justluvgod
11 years ago

This is a great tutorial. I wish I would have located this sooner. One question I do have though; How can I by default display all of the letters A-Z regardless of whether there are no associated documents..for example show A(0)|B(0), etc???.

dc promaster
dc promaster
10 years ago

I want to filter out links to my website content without knowing how? I am using Drupal 7, link following websites [url=http://www.dealhapdan.com/tranh-theu-chu-thap.html]http://www.dealhapdan.com/t…[/url]

6
0
Would love your thoughts, please comment.x
()
x