The Blog Archive - Contextual Filters
admin Fri, 07/22/2011 - 13:28
About 2 posts ago, I mentioned that I would be working on getting the Blog Archive back to the way it was before I did the Drupal 7 upgrade. Before the upgrade I had the Archive setup so that you could go to www.itowler.com/Archive and you would see a listing of Years that have blog postings. The display is looks similar to this: 2011(16), indicating that that there are 16 posts in 2011. By clicking on the year, it brings you to the a Listing of the blog postings by month, and looked similar to this: June (4) etc. All of this was displayed at a URL that looked like this: www.itowler.com/Archive/2011/06 for June. You get the idea, but the cool part of this was that by doing this you could automatically browse to specific Sections of the Archive by typing in the URL that you wanted. As an example, if you type in http://itowler.com/Archive/2009, that would take you directly to the listing of the 2009 Posts. By typing http://itowler.com/Archive/2009/02, you would be shown a listing of all of the Postings for February 2009. This used to be called "Hackable URL's" (I am not sure anyone uses that term anymore) and I thought that it was a really neat feature.
This format / layout was all done using the Views Module, which is quite possibly one of the best modules for Drupal. In Drupal 6 the ability to achieve the "Hackable URL's" was done using a feature in Views called Arguments. In Drupal 7 the term argument has been discontinued in favor of Contextual Filters. Using contextual Filters you can achieve the same thing that you used arguments for, and in fact, I think that the new system is easier to use.
To setup a contextual filter you will need to do the following:
- Open the Views Editing dialog
- Click on the "Advanced" section of the view you are working with
- Contextual Filters is the first section of the advanced tab, so now click "add"
- To set it up like I have mentioned above, add a filter of "Content: Created Year" as well as "Content: Created Month
- Click the "Add and Configure" button
- Click the "Display A summary" radio button, with a format of list. You can add a default path if you want as well. Do the same of the Created month as well.
- Now you should be back out at the Views editing screen. Drag the "Created year" filter so that it is above the "Created Month" (this will apply the year filter first...)
- click save and you are ready to go.
I hope this helps a bit. In my opinion, it is much more straight forward than the old views and makes it a little easier to use.
the term Arguments is not used at all, and instead its called Contextual filters