Using Drupal 7, views 7.x-3.0-beta3. I am trying to make a display containing a list of links which direct users to an archive page containing posts of that month (eg. all news messages posted in march 2011).

Tried to solve this with a contextual filter 'Created year + month', which, when no parameter is given, gives a summary list of links like 'march 2011, december 2010' linking to the URL 'news/201103', 'news/201012'.

Is there a way to change the formatting of that URL to 'news/YYYY/MM' ?

3 Answers 3


You can create path alias to make the URL look how you want, but views need the year and month as a single argument.


You can use hook_url_inbound_alter() to rewrite the paths generated by the Year + Month argument. It's not pretty, but it gets the job done.

The following is for a view with year and month (and day!) arguments at news/archive:

function MODULENAME_url_inbound_alter(&$path, $original_path, $path_language) {
    $args = arg(NULL, $path);

    if (
        $args[0] === 'news' &&
        $args[1] === 'archive' &&
        !empty($args[2]) &&
        strlen($args[2]) === 6
    ) {
        $year = array(substr($args[2], 0, 4));
        $month = array(substr($args[2], 4, 2));
        $remaining = array_slice($args, 3);
        $new_args = array_merge($year, $month, $remaining);
        $path = 'news/archive/' . implode('/', $new_args);

Replace Content: Created year + month with 2 separate contextual filters:

  • Content: Created month
  • Content: Created year
  • Thanks, but that results into a list of months, without years...
    – Stijn
    Jun 1, 2011 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.