(+84) 463.28.7979

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>