How to create a monthly archive block for a Drupal blog with Views

What does a monthly archive block achieve?

I'm not sure how many people actually visit archive links for blogs. It seems like there are more natural groupings of posts, either by tag or the basic pagination, so I think it's likely not a terribly useful browsing pattern. However, there's three things do like about them:

  1. It makes it easier for other people to track your posting frequency
  2. It makes it easier to track your own posting frequency
  3. It helps distributes internal link juice in a permanent way

From what I've heard - and almost all my SEO knowledge comes second-hand - one commonly overlooked method of improving the ranking of a page is using internal links well. Google sees each URL as its own entity, so in addition to garnering incoming links to boost the PageRank of a page, you can also use internal PageRank and it works the same way.

The idea is that each page has a bucket of rank to pass out. If you pass that rank around internally, you can get a nice boost in overall ranking. But, it's important that the links stay constant on a page, since Google tracks the age of links. So while taxonomy pages do a good job of passing out links, the links on their pages may change if they're sorting from newest to oldest.

Archive pages, on the other hand, will always have the same links on each page, so if this internal linking theory is valid, it's a good method to use.

How to set up the archive blog and pages with Views - The easy way

After I put together this blog post, a reader mentioned that there is an archive view that comes bundled with Views. I gave it a test run and it had enough of the same properties of my archive view that I'm pretty sure I must have just cloned it a year or two ago. So, if you want to go the easy way, just enable that and configure it to your liking. If you're wondering how it works or want to set it up manually, read on.

How to set up the archive blog and pages with Views - The manual way

Even though Drupal doesn't come bundled with an archive view like Wordpress, it's pretty easy to set one up with Views.

First, create a new view and add a Block display. 

Set the display to show a high number of items. I want all months to display, so I have it set to 30 for now. The screenshot is from Views 3 Alpha:

Set the filters to match whatever is showing up in your blog. In my case, it's just nodes that are a blog content type.

Next, we need to add an argument for year and month. So, click on the plus sign next to the argument box and select Node: Created year + month:

Next, we just need to select Summary, sorted ascending under Action to take if argument is not present:

You could also select Summary, sorted descending if you wanted the most recent month to display at the top.

By default, the list of months will display as a list with the number of posts per month. This is how I have mine set, and with a little styling it looks like this:

There are a few other options which you can explore by clicking on the link next to Style, which will be List by default and taking a look at the options:

The Jump Menu option sounds neat, but I couldn't get it to work with Views 3 Alpha.

Setting up the archive page

First, add a Page display.

Give the page display a URL:

From what I can tell - and it's been a while since I set this up - the only difference with the Page view is that I've set a title in the argument settings. So, click the override button to make sure this change doesn't apply to the defaults, and then click the edit link for Node: Created year + month and set %1 for the title.

You can test out this page view as long as you have some blog items already. In the Live preview section, add an argument in the YYYYMM format, like so:

In the example above, you would see a list of nodes for July, 2010.

Save the view and then set the block to display using either the block admin page (/admin/build/block) or Context (definitely check out the Context module if you haven't yet for block display settings, it makes SO much more sense). 

That's it, you should be good to go!

Filters Node: Published Yes Node; Type Blog entry DE Block: Add arguments Groups: Node moae: Lreatea montn In the form of MM (01 12). Node: Created week In the form of WW COL -53). Node: Created year jf nt WW Node: Created year month IntheformofYYYYMM. LI In of in /ear in the form of UYYYVM. In of ■lll'll'IMflll NIC ll .he to- n o' he to- 10 01 FY ioae lo-io- Title: The title to use when this argument is present. It will override the title of the view and titles from previous arguments. You can use percent substitution here to replace with argument titles. Use for the first argument, "0/o2" for the second, etc. Breadcrumb: The Breadcrumb title to use when this argument is present. If no breadcrumb is set here, default Title values will be used, see "Title" for percent substitutions. Action to take if argument Wildcard: is not present: [ail If this value is received as an Display all values argument, the argument will be Hide iew Page not ignored; i.e. "all values" found (404) Digplny ampty taxt Wildcard title: Summary, sorted ascending bummary, sorted descending Summary, sorted by number of records jwpnrlinn All The title to use for the wildcard in substitutions elsewhere. [t will to use 15 substitutions. present: If this VALUES i.e, all not o o RJ argument, c.e- de lie cf ler 62 -ecd— nb tie hen sjbslr io is GU ier'1. ar .jrr ei. ■■zli- de nb is is c-rjj LOL SH li Hi Blog archive March 2009 April 2009 15) May 2009 (10) June 2009 f3) July 2009 August 2009 September 2009 October 2009 November 2009 December 2009 January 2010 March 2010(1) June 2010(1) July 2010 (46) March try TMJ ACM (4J (3J CU. UA 2010 March BCN 2010 BCN August June AUG C0a enber be. be 11 2.1 20 20 OS 20' Arguments NODE Created year MON Styt: List Sty LI Status: using default values. Title: Override resent. It will override the title of the view and titles from previous arguments. You can use percent substitution here to replace with argument titles. Use for the first argument, "0/o2" for the second, etc. LCD 62 TSE IL IRA ei. nttl Path d. upai iq, r.r. PAGE .in: SETTINGS el. upai leu, r.r. tl(l»i- Live preview Display: (Page preview Arguments: 201007 Separate arguments with as though they were URL path. Preview") Automatic live argum .jrren ALTOM OTIC Basic settings Machine Name: bkxk NAME Block We rttZUSttS Use pager Paaed. 30 30 tt /ferns More link: Ma Atress: Unrestricted ACCESS 77(fe 30 IM GREET


Comments

You don't have to put all these efforts there is already one by default comes along with views module.

Check out "admin/build/views" page, views name Default Node view: archive (default)

Nice, thanks Sivaji. After looking at my archive block, I'm pretty sure I must have just cloned that one to begin with. I updated the post to mention this time-saver. Cheers!

Hi, I am using the "Monthly archive" from Views module, but I have a problem in the block display, it keeps showing the results in ascending order even if I set descending in the sort options. Does anyone else has this issue?

Thanks,
Antonio

The correct option is the "Summary, Sorted Descending" radio button in the settings for the Date argument. The sort settings don't apply for summary views.

Thank a lot Jake, this worked indeed. The "Summary, Sorted Descending" for the block display was different from the default one. I am adding detailed instructions to this issue report: http://drupal.org/node/857440

Thanks again,
Antonio

Maybe it's possible to create some "limit" (how many months will be visible), and older months to place (somehow) in "older" or something like that.

Sure, you could just clone the view and set it to start at the fifth row, for example, and set that as a separate block.

In "pre-cck&views"-times there was an archive module, delivering just such a block. Obviously, it wasn't necessary to continue it.
This archive function was one point I was "forced" to look at views ;-)

It's nice to go by month, all listed in a row, but what about expandable year-month listings like Blogspot provides? See this blog and the nice archive to the right listed by expandable year: therawandthecookedshow.blogspot.com

Thanks for the tuturial on drupal archives. The archive is working now but my blogpage still shows the content of previous months, how can I clean the blogpage when a new month starts (and a article is written in this new month)? Hope you can help me out

Bump. Anyone? Expandable year-month listings?

How can I filter this by user?
I tried to add an UID arg to the page view. Then create the path: user/%/archive/%

I made sure that the UID arg was first in the list.
Its displaying the right content (only blogs from that user) but its showing the entire teaser for each blog rather than just the Month/Year link...
any hints on how to fix this??

Hi,

I have exactly the same views and its working perfect in localhost and in the live preview but in the real page the content is nothing, and empty text dont showing too.

It can be a server config problem?

im desperated with this issue, the list are showing the correct node count too but it dont work.

thanks

bye

Hi,

Now its working correctly, there was a problem with my block settings
there is not a problem with views

thanks a lot, very usefull blog

bye

Anyone? Summary listings like the following?

2009
- February
- 1 (with option to break down by day or not)
- 6
- 7
- April
- May
- June
- July
- September
2010
- January
- February
- August

Thanks for the response, indeed I would like to break the archive down in years and months in that year. I have tried many setting but for some reason all articles keep showing (www.sebastiaanvandergreef/blog) Hope you can help me out on this matter. Thanks in advance.

Br Sebastiaan

The link to my blog needs to be : www.sebastiaandergreef.nl/blog

Great Tutorial..

Please tell anyone how to show archive in profile page for per user.

After reading article about recent post per user, I could do successfully recent post per user in profile page.

Please now tell how can I do recent archive per user...

Hi Chris

Do you have any knowledge of theming the archive block?

I've ammended the view template by creating views-view--archive.tpl.php etc, so that I could use my custom html, but am finding that whilst the results list (once you've clicked a month) is perfect, the same template is being used for the block displaying the months list (i.e. the argument).

Is there a way to theme the argument list different to the page that displays the results of the selected month?

Thanks

David

Everything perfect, but I do not understand why I haven't the "active" class in the list "month + year"? It's a module?
Sorry my english!

Hi Chris,

thanks for explaining. I does not always help to just copy and paste. Your post saved me a lot of time. Thanks.

Hello, i am new here. Its nice to read some post about this nowadays. Its meaningful and somehow sharing this to readers like me, makes me want to surf the web to be able to get more wonderful ideas.Thank you for posting this. Thank you

Hi,

I have created a content type for users adding news stories, I created a CCK field which allows the user to publish the news item months in the future. Is there a way that I can archive the new stories similar to the above by using the CCK (content: field_publishon) rather than the built-in node created year and month?

I can get the above working by using the arguments within the URL for example www.url.com/news/2011 and if I type www.url.com/news/2010 it will filter correctly. What I cant achive is a list of the months with jan/feb/mar/ etc.

Thanks :-)

hello

I would like to ask how to create this archive block for mulituser blog?
So what I mean. If I will display blog for user20 I get above module where I can see months which user20 posted his/her posts in. If I will display user50 above block will show me months which user50 posted his/her post. If I click on one of the user50 month link eg May 2011, system display list of blog posts created by user50 and published in May 2011.
Any idea how to create it?

Nice article Chris.

I am facing some problem with the archive block.

1. I created a new content type "Blog Post".
2. Clonned the available archive view in Drupal 7.
3. Added filter criteria - Content: Type (= Blog Post)
4. Path is localhost/drupal-7.0/archive
5. I am getting the proper display i.e. May 2011 (2)
6. And getting the archive list if I click on "May 2011 (2)" in Preview.

7. But when set as Block I get messege "The website cannot display the page" - url is like "localhost/drupal-7.0/archive/201105"

Can anyone please help me out.

Regards,
Ashish

I have face same problem? Did you find any solution? Could you please share with me?

hi,

i have planning to create the following format archives for news and events in archives page.

2011 2010 2009 Archives
- January - January - February
- February - February

Please anyone help me, how to create a view for this format archives.

regards,
pandikamal

I managed to create the blog archive monthly block. but I can't figure out how to customize it. Also, when you click on a month and it displays the blog entries for that month, the layout/style of the entries goes back to default ugliness. I want to keep the same layout /custom as my main blog page. why does it change it?

Thanks for the tutorial, it was most helpful :)

I also really like the way you've styled the comments input form.

I'm trying to implement taxonomy menu module but it's now working. I read one of comment that it is not working with i18n.

Is it really these module not working with i18n(multilingual) module? I want to set up taxonomy menu module with i18n module. Could you pls. suggest steps?

Thanks in advance.

Hemant Pancholi

@Jake and @pandikamal - did you ever figure out how to create an archive which is broken down in years as well - and where the years are collapsible:

2011
- January

2010
- December
- November
- Septemer

Nope, not yet... would love to hear if someone else has, though.

there is the wp_blog module that adds this feature.

http://drupal.org/project/wp_blog

Does not currently support multiple languages

Hmm, a little weird, it's description of "Views (which accept year/month/day arguments) for browsing the blog archive" doesn't really specify that it will create year -> month tree in the sidebar... could you verify that you've used it and it really provides this? Thanks!

So, I have found a somewhat hackish way to create an archive broken down by year and then month. I posted a reply with the proposed solution here: http://drupal.org/node/801104

So, I have come up with a solution to this problem. I am a newbie to drupal, so this is probably somewhat hackish. Since it seems like a common need, I have posted my approach here: http://drupal.org/node/801104#comment-5762844

Hi, I'm trying to achieve the above but am struggling at the very end (I've managed to display the archive block by the side of my blog, but I can't get the links in the block to work). I'm new at Drupal (only 2 weeks in!) so something simple may be completely bypassing me! I noticed the first comment here says "You don't have to put all these efforts there is already one by default comes along with views module" however, I can't seem to figure out where this is? Any help would be greatly received. Thanks

I'm running D6 and Views 6.x-2.16.

I see how to limit the number of months displayed on a block. After you select Node: Created year + month and List (default) I selected Summary, sorted descending.

Then there is an option to select:

Display record count with link [check mark]
Override number of items to display [check mark]
Items to display: 12

And if you don't want but a year to be displayed change Use Pager to No.

This is as close as I came to creating something similar to Blogger as simply as possible.