If you impress your first time reader then the chances are very high that he or she may look for your old articles, Unfortunately most of the bloggers don’t make this process simple enough for them, thats why some pro bloggers use an Archive page. An archive page is like a sitemap for your readers to navigate through your buried contents, A reader can easily navigate to your old articles based on a month, year, category and even by tags.
In this simple WordPress tutorial I am going to show you how make your custom archive page within few minutes. Note to Genesis Users – Genesis users integrate the archive page template to the core theme, So just create a new page and on right sidebar select the page template as “Archive” and publish it. Even though its integrated you can still try this tutorial to create your own version of archive page. I have split the process into two parts
- Creating an archive page template
- Creating an archive page
Don’t get confused by the terms, The first part is to create a generic page template for archive which can be assigned to any page to create an archive page. So lets get started.
Creating an archive page template
Create an empty file called page-archive.php and place it in your themes root folder. Now we need to define the code which tells WordPress to treat this file as a page template. Add the following code to the file
<?php /* Template Name: Archives */
Next you need to call blocks like header and bring the entire page inside your content block. To do so add the following code to your file.
get_header(); ?> <section id="primary" class="content-area"> <div id="content" class="site-content" role="main">
Note that css id and class may differ for various theme. The above one is for WordPress default themes like Twenty fourteen and Twenty thirteen. To find it edit your themes archive.php file. Now I am going to define part which is actually displayed in the page.
<?php the_post(); ?> <h2>Recent Articles</h2> <ol><?php wp_get_archives('type=postbypost&limit=10'); ?></ol> <h2>Archives by Month:</h2> <ul><?php wp_get_archives('type=monthly'); ?></ul> <h2>Archives by Category:</h2> <ul><?php wp_list_categories(); ?></ul>
What does these do ? In third line above we are displaying 10 most recent articles, In line 5 we are displaying Archives based on monthly and at the line 7 archive based on category. This is a very simple archive template. You can include plenty of other links like
This is how our final code looks like
Now lets create an archive page.
Creating an archive page
Go to your WordPress dashboard and Pages >> Add New. Name your archive page anything and in right side you can find option to select page template. Choose “Archives” template and hit publish.