How to Create A Custom Archives Template For WordPress

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. Sadly, most WordPress themes do not come with a custom archives page template. In this simple WordPress tutorial, you are going to learn how to make your custom archive page within few minutes.

Creating the Archive Index Template and Page

To set up a separate archive index you’ll need to create it as a Page, and assign it a special template.

Start off with a simple template called archive.php, stored in your theme’s directory. The WordPress Default Theme includes such a template, and it makes a good starting point.

Note: the default theme for WordPress 3.0 and beyond does not have a built in archives template. Something like this should do the trick (you will need to adapt the html structure to match your current theme):

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

<div id="container">

<div id="content" role="main">

<?php the_post(); ?>

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

<?php get_search_form(); ?>

<h2>Archives by Month:</h2>

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

<h2>Archives by Subject:</h2>

<ul>
<?php wp_list_categories(); ?>
</ul>

</div>

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

<!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
[/php]

Technically, the template can be called almost anything (see these two lists for names you should not use; these are special file names WordPress reserves for specific purposes). However, using a standard name for your template will make it easier to change your blog’s theme or distribute your theme and template to the WordPress community. It’s also possible to display a large archive index using one of the all-purpose templates (like index.php or category.php) and the is_page function, but again, taking advantage of the theme system’s modularity makes it easier for others (and for you!) to edit your template later.

The Archives Page

Create archive.php in your theme directory (wp-content/themes/themename/). Then from the Admin Panel, Pages > Add new

  1. Give your new archives Page a suitable title like Site Archives. Leave the Page content blank.

In the sidebar open the Page templates box, and select the Archives template. After saving it you will see a new item in your pages list, click on it, and enjoy!

Customizing Your Archives

List Archives By Year :

To list your archives by year use the wp_get_archives template tag:

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Request a Quote

Let our code do the miracles for your website

We are an award winning web agency with over 10 years of experience in web development. In the past, we have helped numerous businesses establish their online presence through clean and semantic code. Our dedicated team of developers ensure the success of your project by paying attention to detail and by going that extra mile with you until the results are achieved.

</ THEHTMLCODER.COM >

Copyright 2018 - THEHTMLCODER.COM