Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Create a Custom Archives Page in WordPress

Last updated on by
Follow WPBeginner on YouTube
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 fodler 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.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Avinash

    Works Perfectly, When I tried to add &show_count=1 then the count breaks the category listing .. can you help with the css needed for the count to display properly.

  • Pawan Kesari

    Very helpful. I have just added archive page to my blog site
    Question: Would this template file get deleted during theme upgrade?

    • http://www.wpbeginner.com/ WPBeginner Support

      Yes it will, it would be better to create the template file in a child theme.

  • Charlie

    Nice howto, but is there any way to manage something like this in a plugin?

  • Nicole

    I love this tutorial! However, I want my tag cloud to be separated by commas. Here’s the code I used for the tag cloud (I don’t want the font sizes to change so I kept the smallest and largest at the same size)…

    Tags

    Any tips?

    • http://www.wpbeginner.com/ WPBeginner Support

      Your code was stripped by WordPress comments. This snippet should work:

      <?php
       $args = array(
          'smallest'                  => 8, 
          'largest'                   => 22,
          'separator'                 => ','
      );  
      wp_tag_cloud($args); 
      ?>
      
  • voltima

    Thanks a lot for a very easy to understand ‘how-to’.

  • Thomas

    Hi, thanks for the great tutorial!

    I did set-up the list of all categories which looks perfect. The only problem I have is that if I add any content to that page, the list of all categories is always placed at the bottom. Is there a way how I can set it to the top of the page?

  • Archurst O. A

    Is there a way to show per day or week instead of the monthly archive style?

  • sameera

    Thanks. Grete work.

  • Nad’

    Hello guys,
    First of all, thanks for this amazing website. I have used this post to create the archive but since yesterday the archive page is no longer working. I have not changed the code and now the only thing I see is By date. after that, I cannot see anything, not even the sidebar or the footer.
    My template is running locally as I am building it. Any idea what could have caused that?

    thanks

    • http://www.wpbeginner.com/ WPBeginner Support

      seems like a coding error in your template is breaking the template right after it displays your archives by date.

  • meki

    I copied your given code but my site is not showing any kind of archives. Your code has an error. 0n line # 16 you are closing ?>php then starting html, which will simply print html on page. I activated plugin, corrected the code but still my page is empty. Let me correct, thanks.

    • Meki

      I do not have a page.php as well.

      • Meki

        any reply?

        • http://www.wpbeginner.com/ WPBeginner Support

          Meki, we are sorry but we are unable to understand the issue you are facing. As for page.php file you may be using a Theme Framework so your theme may not show a page.php file. Please contact your theme author and ask them which file you should use as the base for your custom page templates.

  • Craig Parker

    Awesome. I’ve got to bookmark it and come back, but an archves page is something I’ve been wondering about for a bit now.

  • Kelly

    Great tutorial. Could you clarify something before I begin. I’m using a child theme. Should I add the page-archive.php file within the folder of the actual “theme files” or should I place it within the child-theme-folder? Likewise….Now we need to style this list, make it appear inline and improve their look. Add this to your theme’s style.css file. I’m going to assume I can add this within my child-theme as custom css; is that the correct approach?

    • http://www.wpbeginner.com/ WPBeginner Support

      Yes this is the correct approach.

  • gary bvings

    I’d like to combine the two archive display ideas above. I have two categories: Cars and Boats. I’d like to show the monthly archives ( with the Compact Archive plug-in) for each. What php do I use? Thanks.

  • Maschil

    Great tutorial — thanks :) It has worked perfect!

    I copy and pasted the css provided into my css file and it did not change the look at all. Thoughts?

    • http://www.wpbeginner.com/ WPBeginner Support

      It depends on where you copy pasted your CSS.

  • Kate Reid

    Thanks so much for this really useful post. I’ve just started using a really minimal theme, so this custom archive page is perfect to help navigation. It’s looking good!

  • nicole holgate

    Hi,

    Great plugin and easy to use.

    I am trying to use it for a custom posts archive page (only the custom posts to be listed in years, by month.

    Does this work with custom post types at all? Currently it is only listing regular post types.

    With thanks :)

    Nicole

  • Emily

    Ok I think I’ve figured out where to upload it, but now it’s not supporting my notepad file.

    • http://www.wpbeginner.com/ WPBeginner Support

      Make sure that your file name is page-archive.php and not page-archive.php.txt or page-archive.txt

  • Emily

    I do not understand where to upload my page-archive.php file. Where is the WordPress Theme folder?

  • Sheeba Yousuf

    I have created Archives.php and when on the page i click on the archives i don’t get which template is the posts using (custom posts) ,its a mess actually. Could you please help.

  • Chris Raymond

    i see you are using the_content in the loop, but when you click on a month and see the posts, it is only showing a snippet. Is that controlled via another custom function? Could I instead use the_excerpt?

    TIA, very useful post

  • real name

    good work man …kepp it up

  • Atanas

    Well… This post is quite useful but I got problem… I have Thesis 1.8 theme and I am not able to find page.php file in my theme folder …. Sad… Any ideas…

    • http://www.wpbeginner.com/ WPBeginner Support

      Thesis is a theme framework you need to check Thesis Documentation to learn how to make these changes.

  • Saranya

    Great tutorial. It helped me a lot as a beginner. Thank you so much.

  • Syed Irfan

    Syed, you are doing a great job for the beginners, and I think its a great service specially for the very non skilled just like me. Masha Allah and JazakAllah!

  • Carol

    Is there any way to limit the output from Compact Archives to one category of posts instead of all posts?

  • Kenny

    I found it too difficult to add to a Woo Theme. The Woo Framework page.php is too complex to work out where the additional Compact Archives code goes. It doesn’t have a nice commented slot as does the sample in the example.

  • Nusa Herba

    We’re trying to create something like this, thank you for the tutorial, very useful.

  • Kenny

    So timely! In the last fortnight I have been frustrated at how difficult it can be to view archive posts in time sequence and some other ways. And I wondered whether my readers were having the same issue. I’m not into adding code but will make an exception in this case. Thanks.

  • Amy

    Nice tut!