There has been much debate over the value of displaying your archives on your WordPress blog. Some people are all for it, while others feel that you should move any archives to their own page. No matter which camp you are in, I think both can agree that if you do display your archives, you do not need to display an overabundance of them.

By default, most WordPress themes come with some standard code to display your blog’s archives by month and with no limit to the number of archives to display. Typically the code will look something like this:

<h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>

This will be fine for the first 6 months are so, but once your blog gets a little more established, you’ll probably notice that the number of months displayed are never ending. This can quickly become an eyesore for your blog and people generally won’t want to look at archives more than 6 months old. In order to set a rotating limit of months displayed on your blog, you simply need to make a small change to the above code to add a limit:

<h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly&limit=6'); ?>
</ul>

If you want to display more or fewer months, just change the 6 accordingly. Its really that easy!

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Connect with Kyle on Twitter or Google+!

  • Pingback: Collection of WordPress Hacks

  • Pingback: 100+ Killer Wordpress Resources | Steffan Antonas’ Blog

  • qoman

    wow thank you for this trick i’m searching this’s work for me !!

  • http://www.doliver.co.uk/ David Oliver

    Just the thing. :) Thanks.

  • kym

    If I have posts in June and post in October and limit to 2, it is not showing September (empty) and October. It is showing June and October. How do we do last two calendar months rather than last 2 months based on posting?

  • sim

    this doesnt work with widgets dynamic sidebar

  • http://mx.anunciamex.com/ Sophie

    Thank you, WordPress is so flexible.

  • kiran

    This is not working for me and I an frustrated. I am using the Inove template.

    Please help

  • http://www.ramzblog.wordpress.com Ram

    thanks for ur help
    now i have a doubt how the categories can be limited in the sidebar of wordpress theme

  • Jenny Allen

    Dunno why I can never remember this. Thanks!