How To Build A Custom Archive Page Or Site Map For Your WordPress Blog

When I started blogging then I wanted to build a page or site map that would show the monthly archives in that page so that the visitor can see all the posts at a glance. But it was difficult to me to know the process and I was quite upset. But after trying for a long time I found out the actual process. Though I found some plug-in to do the same job but I didn’t want to use any plug-in for this purpose. It is quite easy to setup manually. You can do this using the feature inbuilt in WordPress. WordPress supports to add a page as a template page. You have to use this feature.
How to build the custom archive page for your blog
We shall use the page attributes of the page which depends on the theme of your blog.Generally it is named as “page.php”.Now copy the content of the page.php and paste it in another php file suppose it’s name is ‘page-archive.php’.
Now open the “page-archive.php”.
At first add
<!--code-->
<?php
/*
Template Name: Archive-Page
*/
?>
<!--end code-->That will help to identify the template page, when we create the archives page in the WordPress back-end
in the very first portion of the page.
Now find the line containing
“<?php if (have_posts()) : ?>”Delete all the line up to the line containing
“<?php endif; ?>”Now the page template is ready for your use.
Here the area where we can write your desired code:
<?php get_header(); ?>
<div id="content" class="left-side-padding">
<!--Here is where our code will go-->
</div>
<?php get_footer(); ?>Now put the code give below in the specific position in the “page-archive.php” where you want to show the monthly archives.
<! --start code-->
<?php
// Declare some helper vars
$previous_year = $year = 0;
$previous_month = $month = 0;
$ul_open = false;
// Get the posts
$myposts = get_posts('numberposts=-1&orderby=post_date
&order=DESC');
?>
<?php foreach($myposts as $post) : ?>
<?php
// Setup the post variables
setup_postdata($post);
$year = mysql2date('Y', $post->post_date);
$month = mysql2date('n', $post->post_date);
$day = mysql2date('j', $post->post_date);
?>
<?php if($year != $previous_year || $month != $previous_month) : ?>
<?php if($ul_open == true) : ?>
</ul>
<?php endif; ?>
<h3><?php the_time('F Y'); ?></h3>
<ul class="month_archive">
<?php $ul_open = true; ?>
<?php endif; ?>
<?php $previous_year = $year; $previous_month = $month; ?>
<li><span class="the_day"><?php the_time('d'); ?>:</span>
<span class="the_article">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?>
</a></span></li>
<?php endforeach; ?>
</ul>
<! -- end code -->That are the code to build a custom archive page for your WordPress blog.Now you can change the design of the page editing the css file.
Here the screen shot of the archive page of my blog.
I think there should be no problem to build the monthly archive page of your own blog.What are you thinking?Is it not pretty easy process?Now which choice you will prefer:plugin or the above method?
How to add more features in your blog archive page
After creating Your archive page you would want to customize your archive page.I am giving you just an example:
Suppose you want to show a certain numbers of word of your content with each post link in the archive page then what will you do?Here is the process .
1.Open the function.php file of your theme.Then put the following code there.
function excerpt($num) {
$limit = $num+1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)."...";
echo $excerpt;
}
function content($num) {
$theContent = get_the_content();
$output = preg_replace('/<img[^>]+./','', $theContent);
$limit = $num+1;
$content = explode(' ', $output, $limit);
array_pop($content);
$content = implode(" ",$content)."...";
echo $content;
}Now Find Out the line containing the following code from the above which you created earlier.
<li><span clas="the_day"><?php the_time('d'); ?>:</span>
<span class="the_article"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a></span></li>Replace it by
<li><span class="the_day"><?php the_time('d'); ?>:</span>
<span class="the_article"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a>
<?php excerpt('Put the number of word you want to show'); ?>
</span></li>What is your choice ?Plug-in or manual process to build a custom archive page for your WordPress blog?
Please leave a comments.
3 important tips to chose a blog name

Reader Comments
Very good tanmay. Actually i use a Plugin called clean archives reloaded which creates an archive page using a javascript.But you have done a Great Job by creating the same page without any plugin.It may be difficult in the begining but nothing comes easy …. right ??
Great article. I appreciate your work.
Thank you Amit.I always prefer not to use any plugin if the same job can be done manually……..
Thank you again for sharing your experience.
Awesome, Tanmay. Thanks for sharing this. I don’t like using plugin unless I absolutely need to. This is simple and does exactly what I want it too.
Thanks again.
@Jacob Classidy: Glad to know that my article has helped you. Anyway thanks for commenting. Keep reading.
Thanks for that piece of code Tanmay, I will make an archive page of my blog now.