Tutorial: blog archives with individual nodes listed in Drupal 7

Introduction
This is the first tutorial I have posted on this blog. It's only a short one, because most of the material is hosted elsewhere.

Why do we need another blog archive?
The blog archive blog has become a staple of blogging websites. It lists content in a summarised way, usually by Year + Month, and as far as I know it was pioneered and popularised by platforms such as Blogspot and Wordpress.

On Drupal, however, it has mainly been left to Views to produce such blocks, and while the result is usually good (and very tolerable!) it tends to be about providing links to other view pages from within a block (this tutorial exemplifies that approach). However, one of the requests I get quite often from development clients is to have the actual content listed beneath the monthly summaries.

In Views, that can be a bit of a pain to create, because grouping content by Year + Month summary is actually not very simple under the Views interface.

A quick custom module
Because of this, I decided it would be a good idea to knock up a quick (still fairly rough-and-ready) custom module to provide this functionality. It does the following things:

  • Declare a block
  • Get all published nodes of type "article" using an Entity Query
  • Sort those nodes by date created (most recent first)
  • Prepare a simple nested array to organise the nodes by Year -> Month - > Title [Path]
  • Recursively pass over the array to create the list markup
  • Output the markup in a block

I also included some very simple CSS and jQuery snippets to get you started on theming the block.

Start using it!
Head over to GitHub to download the module, upload it to Drupal in the normal way, enable it and place your block wherever you like (e.g. in a sidebar).

If you would like to contribute to improve the module in any way, feel free to do so on GitHub or drop me an email via the contact page.