Free Wordpress Blog Setup

How to Limit the Number of Archive Months Displayed in WordPress?

By Editorial Staff in Tutorials
How to Limit the Number of Archive Months Displayed in WordPress?

If you visit some blogs, their sidebar is filled with archive months. There are some people who like to have archive links in the sidebar because they want their user to browse easily, and there are some who just want to show how old their blog really is. But to the majority of the users, having 26 months listed in the sidebar is a waste of space. Therefore we will show you how to limit the number of archive months displayed in WordPress.

In most themes, you will see the code in sidebar.php to be some what like this:

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

These codes are the default ones that come with many theme. It works out perfectly fine for the first few months, but as your blog gets older, it becomes a clutter in the sidebar. So you should change it to the following codes:

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

You can change the number 6 to the number of your choice. This is a perfect compromise for those who want to help users browse few older months, but not have clutter. In our next tutorials we will show you how you can make yourself a custom Archive page for WordPress.

What Next?

Digg it
Save This Page
Subscribe to WPBeginner
Stumble it
Free Wordpress Blog Setup

Comments

2 Responses to “How to Limit the Number of Archive Months Displayed in WordPress?”
  1. Dave Jones says:

    I don’t think this will work if your theme is widget enabled (most modern themes are). In general changing sidebar.php is only useful for older, non-widget enabled themes.

    Instead, you should use something like Breukie’s Archive Widget which allows you to set parameters like type and limit in the options.

Share Your Opinions

Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!

Please make sure that you have read our Comment Policy.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar