How to Create a Custom Archives Page in WordPress

Custom archives page is a great way to bring together all your old content in one page. It allows you to have a dedicated page where you can list your monthly archives, category archives, tag archives, author archives, and anything else that you might want to add. We have a custom archives page for WPBeginner. Recently one of our users suggested that we write a tutorial on that. In this article, we will show you how to create a custom archives page in WordPress.

The Problem

By default, you have the ability to display your yearly archives by using sidebar widgets. This can get out of hands once you have been blogging for more than a year. Imagine sites like WPBeginner that have been active for nearly 4 years. We would have 48 monthly archive links in the sidebar. You also have the ability to add category archives, author listing, etc on your sidebar. But why clutter the sidebar with so many links when you can create a single page to list them all. This is when a custom archives page come in play. Not only does it allow you to avoid clutter, it also provides your users with an efficient way to browser through your older content.

Sadly, most WordPress themes do not come with a custom archives page template. Let’s look at what you need to create a custom archives page template in WordPress.

Note: Please do not confuse the custom archives with archive.php template that comes with most WordPress themes. The archive.php template is used to display monthly, category, tag, author, and other archive pages. Our custom archives page would be a single page that will bring all of your other archives together.

Creating a Custom Archives Page Template

First thing you need to do is to create a page template for the custom archives page. Simply open a new file in your text editor (i.e Notepad) and name it page-archive.php. Next, Add the following lines of code at the top:

<?php
/* 
Template Name: Archives
*/
?>

Upload the page-archive.php in your WordPress themes folder, and you have created an Archives page template. Now we need to make sure that this page template matches the design of your site. Copy the content of your page.php file located in your theme’s folder and paste it in page-archive.php.

Below is an example of how your page-archive.php file would look like:

<?php
/* 
Template Name: Archives
*/
get_header(); ?>

<div id="primary" class="site-content">
<div id="content" role="main">

<?php while ( have_posts() ) : the_post(); ?>
				
<h1 class="entry-title"><?php the_title(); ?></h1>

<div class="entry-content">

<?php the_content(); ?>

/* Custom Archives Functions Go Below this line */



/* Custom Archives Functions Go Above this line */

</div><!-- .entry-content -->

<?php endwhile; // end of the loop. ?>

</div><!-- #content -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Creating a Custom Archives Page in WordPress

Now that you have the basic page template ready, you need to create a new custom archives page in WordPress. Go to your WordPress admin panel and add a new page (Pages » New). You can call this page Archives, Library, or anything else that you like. Now look at the meta boxes below the publish button on the right hand side of your screen. You should see a meta box called Page Attributes. Click on the drop down menu below Template and choose Archive as your page template. Save and Publish the page.

Select Archives Page Template in WordPress

Now you have created a page that uses the archives page template, however it will not show any content. Let’s go ahead and add custom archive page elements such as yearly archives, categories, etc.

Adding Monthly Archives with Compact Archives

If you look at our custom archives page, then you will notice that we are not using the default monthly archives listing that comes with WordPress. Instead, we are using a plugin called Compact Archives. Note we have adopted this plugin and are now maintaining it.

Install and activate this plugin the Compact Archives plugin. After activating the plugin, add the following code in your custom archives page template (page-archive.php):

<p><strong>By Date</strong></p>
<ul>
<?php compact_archive($style='block'); ?>
</ul>

It will display your monthly archives like this:

Displaying monthly archives one year per row using Compact Archives

Adding a List of all Categories

Categories summarize the main topics of your website and are the best way to sort your content. See why how we use Categories vs Tags. Since we are using categories as the main way to organize our content, we think it is absolutely crucial to list our category archives. To save space, we are going to display it an inline list.

First add this code in your archives page template file:

<p><strong>Categories:</strong></p>
<ul class="bycategories">
<?php wp_list_categories('title_li='); ?>
</ul>
<div class="clear"></div>

Now we need to style this list, make it appear inline and improve their look. Add this to your theme’s style.css file:

ul.bycategories {
margin: 0;
padding: 0;
}
ul.bycategories li {
list-style: none; 
list-style-type: none;
margin: 0; 
padding: 0;
}
ul.bycategories li a {
list-style: none; 
list-style-type: none;
margin: 0 20px 15px 0; 
float: left; 
background: #eee; 
color: #464646; 
padding: 5px 10px;
border-radius: 5px; 
-moz-border-radius: 5px; 
-webkit-border-radius: 5px;
}
ul.bycategories li a:hover{
text-decoration: none; 
background: #ff6200; 
color: #fff;
}
.clear{clear: both;}

Your categories will look like this:

Displaying in line categories on archives page in WordPress

Explore? Redirect Users to a Random Post

In our archives page, we have an Explore WPBeginner button. This button redirects users to a random post. The purpose is to allow users to randomly stumble through articles. Learn how to redirect users to a random post in WordPress.

While this is all the information that we have on our custom archives page, you can most certainly add more. Let’s look at some of the other things that you can add.

Adding a Tag Cloud

If you want to display a tag cloud of your most popular tags used on the site, then simply add the following code in custom-archive.php file:

<p><strong>Tags Cloud:</strong></p>
<?php wp_tag_cloud(); ?>

The wp_tag_cloud() function comes with a lot of parameters to adjust the number of tags, maximum and minimum tag sizes, etc.

Adding a List of Pages

If you want to display a list of all pages on your site, then simply add the following code:

<?php wp_list_pages( 'title_li=' ); ?>

Adding a List of Authors

To display the list of authors on the site, simply add the following code:

<?php wp_list_authors( 'exclude_admin=0&optioncount=1' ); ?>

Adding Recent Posts

If you want to display a list of your most recent posts, then add this code:

<?php wp_get_archives('type=postbypost&limit=10'); ?>

A comprehensive archives page allows your users to efficiently navigate through your old content. We hope that this article helped you create a custom archives page in WordPress. If you have any questions or suggestions, then please let us know by leaving a comment below.