Creating a Blog Archive using Views Accordion

Submitted by Brandon Cone on 07/15/2013 - 08:39:am

I was creating a blog for a client's website the other day and wanted to implement an archive feature as part of it.  Now, surely blog archives are nothing new to most Drupal developers and site builders - we use these for tag clouds, monthly archive lists, etc quite frequently.  My goal in this instance was to not have a long list of entries grouped by month but to have a nice, collapsed list out of the box ready to pass off to theme work.  If you've worked with this before, you know that grouping by Created/Updated Date can be a little tricky because, even though two posts were created on the same day, they don't have the same timestamp.

What I found for this task was pretty straightforward once I figured it out but there weren't many examples of it so, here you go:

  1. Create your blog view.  Chances are it is going to be a page view.  Once you have this done, create a block display which will display the Created Date (I used a custom formatter to display Month, Year (F, Y)) and set it to Excluded From Display.
  2. Update the display settings for this block to use Views Accordian.  If you haven't used views accordian before, you should know that its default behavior is to use the first field in your fields list as the "Accordian Field."
  3. Go to the Fields settings of your block display and set the Created Date as your Grouping Field 1.  In normal list displays this will cause all of your output to be grouped by the Month, Year as configured above.  As previously mentioned, V_A doesn't quite work like this so.
  4. In the fields settings, select "Use the group header as the accordion header."  This will override the default accordian behavior so that your grouping field becomes your accordion field.  

Now you've got an archive block for your blog which groups all blog posts by month into a handy accordion block.

Happy Site Building!  

Blog Photo provided  by  aturkus