WordPress allows sites to create list of posts based on date. You may have seen this on other sites and your own site, that’s probably why you are here. The problem is the list gets bigger and bigger, the longer your site has been around. So, let’s take a look at how-to limit the date-based archive list to display a certain about of items.

Steps to Take

The archive list will be displayed on the sidebar, so if you want to limit the number of items shown, open your theme’s sidebar.php and look for the WordPress function called wpgetarchives.

The WordPress function called wpgetarchives, will look like this or a variation of this:

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

Or, it could be constructed into an array, meaning many options, that looks like this:

<?php wp_get_archives( array( 'type' => 'monthly', 'order' => 'DESC' ) ); ?>

Now, in both examples you’ll see type=, and this is the type of date you want to target. The type can be: yearly, monthly, daily, and weekly. Monthly is the default.

Limit The Number Displayed

Now, you need to add and define an argument called limit. This is what it would look like in both examples:

<?php wp_get_archives( 'type=monthly&limit=5' ); ?>
<?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 5 ) ); ?>

You’ll notice in both examples, I’ve set the limit to 5, which is a reasonable number in my humble opinion, but you can set the number to what you want. You’ll also notice in the second example, the number five (5) is not wrapped in single quotes and it should not be, since it’s a number and not a word.

If you wish to learn more about the wp get archives function and the arguments you can make, check out this page.