Drupal Quick Tip: Easier “Archive” Filtering

I was working on a project today where we needed to show an archive of announcement nodes. The sidebar had to show a listing of months like this:

archive

This is easy to accomplish by using the default Archive view that ships with Views, or by creating your own view that uses the same contextual filters, block and page. The contextual filter most typically used is Content: Created year + month. Here’s what the settings look like for this contextual filter:

settings

What if the node’s created date isn’t the date by which you want to group your archives? Well, you can either work it out using other contextual filters, or, if it doesn’t affect other handling of this content, you can simply updated the created date to match the other date that you want to group by. I’ve chosen to do the latter, which I accomplished through a very simple Rule:

reaction_rule

With this rule active, any time someone creates or updates an announcement node, the created date will automatically be set to the value of the field_announcement_date (a date field in this content type) field.

Tagged with: , , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*