| Drupal

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


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


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


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.


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


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


Editing the View


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:


Modifying the View's Fields


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:


Click on "User: Name Author"


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:


Filtering Out the Nodes in the View


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.


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".


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.


Now that you've made those changes, finish off by clicking "Save" at the bottom of the page.


That should be the final step

The End Result


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.