Skip to content

Creating an Alpha Pager with Views 2 and Drupal 6

1 min read

UPDATE: Earl comments below how this is already built in. Two different ways to achieve a similar result, each with their own pros/cons.

Hats off to Earl Miles and the rest the views developers they have done a tremendous job with Views 2. While the interface is entirely different from that of Views 1, it is so much more intuitive that within a few minutes I had quickly forgotten my bewildered “oh no, I know nothing” look :)

From reading all of the docs and quietly watching development commits, I knew Views 2 was going to eliminate a lot of the Views 1 helper modules and open up a whole new world of awesomeness. While I haven’t seen many blog posts detailing just which functionality/modules have been replaced with Views 2, I wanted to kickstart things with my own discovery as I played around with Views 2 quite thoroughly this afternoon.

With Views 1, to build an alpha pager you would use the views alpha pager module in conjunction with your view. But what about Views 2?

Well it’s not so straightforward. I read somewhere about some sort of “glossary” view, but how could that be used to create an alpha pager? Well turns out, quite easy. Here’s how:

  1. First, create a new page view and set your path to "directory"
  2. Assuming you want your pager to be based on the nodes title, add in an argument: "Node: Title"
  3. Set title equal to: "Directory: %1"
  4. Action to take if argument is not present: "Display all values"
  5. Check "Glossary Mode"
  6. Set character limit to "1"
  7. Case: "upper case"
  8. Case in path: "lower case"
  9. Save and update
  10. Add in a header under basic settings
  11. Set up your alpha pager:
<div class="alpha-pager">
  <a class="alpha-page" href="/directory/a">A</a>
  <a class="alpha-page" href="/directory/b">B</a>
   ... 
</div>

Note: if you have PHP filter enabled, you can set up proper links using l(), otherwise use basic HTML

And voila! You can now browse by starting letter of each node. Add in a few more exposed filters like taxonomy terms or search and you have a powerful directory!

That was definitely easy and Views 2 replaces its first helper module. What’s next? :)

codeDrupal

Related Posts

MothersClick Acquired by Lifetime Networks

MothersClick.com [http://www.mothersclick.com/] and the rest of the ParentsClick Network [http://www.parentsclick.com/]have been acquired by Lifetime Entertainment [http://www.marketwatch.com/news/story/l/story.aspx?guid=%7B764B126C-2071-4605-8222-7FA1E481B0EE%7D] . I’ve been working on this site and with Dietrich (CEO & founder) for over 2

news — 5 min read

Leo talks about the new TWiT.tv site

At the end of last week’s TWiT episode [http://www.twit.tv/62], Leo and company talk about the new TWiT.tv site [https://tedserbinski.com/drupal/twit-tv/]. A clip of that can be listened to below. Also last week on the Lullabot podcast [http://www.lullabot.com/podcast]

code — 1 min read

My first 15 min of fame!

A few weeks back, Leo Laporte [http://en.wikipedia.org/wiki/Leo_Laporte] approached Lullabot [http://www.lullabot.com/] about developing the new TWiT website [http://www.twit.tv/]. Well we gladly accepted, I mean, this is Leo! So I was put in charge of developing the new site, and

code — 1 min read