Create a Wordpress-like archive with Drupal 7

One of the things I liked with Wordpress was the post structure. The full URL for a post being:

http://domainname.bla/weblog/2011/01/01/full-title-of-blogpost

The date representation allows filtering by (parts of) the date. I wanted to keep this after migrating to Drupal 7.  Implementing this on Drupal 7 needs configuration of 2 parts: a content type and a view. We configure the URL for the content type to include the date in the correct format. The view is configured to allow the visitor to see an overview of the posts, filtered by (parts of) the date. 

The Content Type

  1. Created a content type 'Post' with your desired fields.
  2. Install the module Pathauto and activate it.
  3. Click 'URL aliases' under 'Search and metadata', on the configuration page in the back-end.
  4. Click the tab 'Patterns'
  5. Enter following pattern for your content type 'Post':
    weblog/[node:created:custom:Y]/[node:created:custom:m]/[node:created:custom:d]/[node:title]

    This will include the different parts (year, month, day) of the creation of a post into the url alias pointing to that node.

Direct links to our new content type are handled now. Now the handling for the view.

The View

  1. Install and/or activate the Views module. 
  2. Create a new view (Structure > Views > Add new view)
  3. Use the following settings:
    Show Content of type Post tagged with  sorted by Newest first
  4. Let Drupal create a page for this view with the following url:
    /weblog
  5. Let Drupal generate a menu item if desired.

We've created a simple view at this moment. We want this view to handle the following URL's:

http://domainname.bla/weblog/2011
http://domainname.bla/weblog/2011/01
http://domainname.bla/weblog/2011/01/01

The different date parts are parameters. These parameters are called 'Contextual filters'. Follow these steps to configure them:

  1. Unfold 'Advanced' and click 'add' next to 'Contextual filter'.
  2. Select these 3 items in the list showing up:
    1. Content: Created year
    2. Content: Created month
    3. Content: Created day
  3. Hit 'Add and save contextual filters'
  4. All default settings are ok. You can however override the title according to the used filters. (Pick 'Override title') I used these ones:
    1. For the year: 'Show posts for the year %1' (%1 will be replaced by the year given in the url, for example 2011)
    2. For the month: 'Show posts for %2, %1'  (%2 will be automatically replaced by the name of the month, for example January)
    3. For the day: 'Show posts for %2 %3, %1' (%3 will be replaced by, you got it, the day of the month)
  5. Hit 'Save'.
  6. It's done! Test it.