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:

<?php wp_get_archives('type=monthly'); ?>

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:

<?php wp_get_archives('type=monthly&limit=6'); ?>

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 as a place to share hacks, tutorials, etc. Follow Kyle on Twitter @KyleEslick!

  1. qoman says:

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

  2. David Oliver says:

    Just the thing. 🙂 Thanks.

  3. kym says:

    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?

  4. sim says:

    this doesnt work with widgets dynamic sidebar

  5. Sophie says:

    Thank you, WordPress is so flexible.

  6. kiran says:

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

    Please help

  7. Ram says:

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

  8. Jenny Allen says:

    Dunno why I can never remember this. Thanks!

Trackbacks/Pingbacks »

  1. 100+ Killer Wordpress Resources | Steffan Antonas’ Blog says: