PHPMatters Help You Better Hosting Your PHP-based Sites
How to Create a Custom Archive Page in WordPress

How to Create a Custom Archive Page in WordPress

Usually, an archive page is a great way to showcase all your old/new archives on a dedicated page, such as category archives, monthly archives and tag archives, etc. As is often the case, it is crammed with all those mentioned archives’ links as a sidebar widget of a WordPress site. But why confuse your readers with so many links when you can build a custom archive page to display them all?

To say the least, there are still many archive pages completely-neglected and poorly-organized, which results in bad user experiences. In this case, we would like to showcase how to make full use of a custom archive page to bring your old or new blog content together. Now, move on and get more details.

Check Whether You Have an Archive Template

As is mentioned above, a dedicated archive page allows your visitors to search and scan your archive content with least effort. And things will become much easier if there is a default archive template available in WordPress. In this case, it is recommendable to check if you have an archive template on your WordPress site in case.

To do so, you can simply “Edit” or “Add” a blog page (not a blog post) on the WordPress dashboard. As is showed in the following screenshot, you will see the “Page Attributes” menu where you are allowed to assign the previously-created custom page template to any WP page. And if you have an archive page template by fault, then you will notice a viable option like the below “Custom Archive Page.”

WordPress Archive Page - Check Archive Template

Note that the name of your archive template is not fixed, which means that you can create your favourite archive template name in the “Templates” file. As such, you are able to name it as “Archives” or “Archive.” It needs to point out the built-in archive.php file is different from the custom archive template file. Because the former one works to display author, date, taxonomy and many other archive pages, while the latter one is specially used to add a custom archive page template.

How to Create a Custom Archive Page Template in WordPress?

At the very beginning, we would like to outline what you need to add a custom archive page template manually. To do this, you will need to go into your “Templates” file, which can be done both through the admin panel and the WordPress dashboard. Here, we prefer to login to the cPanel admin panel and access the “themes” folder by clicking on the “File Manager.”

WordPress Archive Page - Login Admin Panel

Once done, you will be able to create a new file named as “page-archive.php” file for your custom archive pages. To do this, you should click the “New File” option lying on the left top of this page. Do not forget to click on “Create New file” to take effect.

WordPress Archive Page - Create New File

And then, you should open this newly-created file by choosing “Edit” option. Now, copy and paste the following shortcode to this “page-archive.php” file. Remember to click “Save” button to make it work.

<?php
/*
Template Name: Custom Archive Page
*/
?>

If done properly, you will be able to see the mentioned “Custom Archive Page” option in WordPress. Now, all you need to do is to ensure that this newly-created archive page template will match your WordPress site’s design. To be frank, the most recommendable way is to copy the content of the page.php file that is located in the same theme’s file folder. Of course, you can also use the code of archive.php file.

Whichever method you decide to use, you should make sure that you will delete the main content’s code in the page.php or archive.php file. That is to say, you are required to start with the header attribute of “get_header(); ?>” and end with the footer attribute. To make things easy-to-understand, we would like to display a sample of the newly-created page-archive.php file based on the page.php file’s content.

<?php
/*
Template Name: Custom Archive Page
*/
?>

<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">

/* Your Custom Archive Functions Should Be Put Here */

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

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

Beware that your archive page template’s code would be a tad bit different from the above one, which is determined by your current theme.

How to Create an Archive Page on Your WordPress Site?

Till this step, you have already added an archive page template in WordPress. And now, you should go back to the WordPress dashboard and enter “Pages” > “Add New” to create an archive page. As you may imagine, you can fill in any post title and content as you like.

WordPress Archive Page - Create Archive Page

After that, you should go to the “Page Attributes” area to select the “Custom Archive Page” option from the drop-down menu of “Template” before publishing this page. So far, you have successfully created an archive page in the basis of the custom archive page template.

Archive Page Choices?

To customize an archive page varies from person to person, and it based on personal appetites. In this case, we would like to demonstrate several important aspects during the entire process.

Add a New Listing of Monthly Archives
As such, it is advisable to make use of a simple WP plugin named as “Compact Archives” that empowers you to showcase a monthly archive of your posts in a concise and eye-catching form. To get started, you should search and install this “Compact Archives” plugin in the “Plugin” > “Add New” area.

WordPress Archive Page - Install & Activate Plugin

As is displayed, make a click on the “Install Now” button and you will be prompted to “Activate” this plugin. If completed, you will be taken to the “Installed Plugin” page where you can choose to “Edit” and even “Deactivate” the “WPBeginner’s Compact Archives” plugin.

WordPress Archive Page - Edit & Deactivate Plugin

Then, go to “Appearance” > “Widgets” and you will notice the “Compact Archives Widget” option in the “Available Widgets” area. All you need to do is to drag this option to the right “Main Widget Area” so as to put the monthly archives onto your site. As is showed in below, you are allowed to create any archive title you like. In the meantime, you can select your favourite archive style ad transform text to “UPPERCASE” or “Capitalize.” At last, click on “Save” to take effect.

WordPress Archive Page - Compact Archives Widget

Add a Listing of Categories
In addition to monthly archives, you can also add a listing of categories to the custom archive page. To do this, you can refer to the following shortcode and paste them into the page-archive.php file.

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

Add a Listing of Recent Posts
In the meantime, you can also display WordPress recent posts in the archive page by making use of the below shortcode.

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

Apart from those mentioned aspects, there are many other WordPress template tags that are used to enrich your archive page template. Here, we make a list of some significant ones in the following part.

  • wp_list_pages() – It showcases a full list of your blog pages.
  • wp_list_bookmarks() – It showcases a full list of your blog URLs.
  • wp_get_archives() – It showcases a full list of date-based archives.
  • wp_list_comments() – It showcases a full list of comments on pages/posts.
  • wp_tag_cloud() – It showcases a full list of your tags used in the tag cloud.