Nov18

Archives

I recently modified my archives page to help people find content more easily. My archives page has a list of the months with collapsable posts during that month, this is powered by the SRG Clean Archives plugin for WordPress. It also has a tag cloud and category cloud which are part of my Archives template. Demo

How to Do it

WordPress has the ability to create styles for types of pages other than what is in the index.php file. This allows you to add things to single post but not every-page, a helpful way to understand this is this image. WordPress offer a template for Archives called Archives.php, but this styles the pages where the archives are shown. So what if you want to change the page where all the archives are managed i.e. http://rmaspero.com/archives. WordPress also offer a thing called page templates. This allows you to create a page in WordPress and change that pages individual template.

Page Template

Now if you open your FTP Client and duplicate you index.php file. Delete the loop and everything inside the loop(that is the bit that goes <?php if post ect.. and until it goes <?php end ect…). Then add this to the top of the document, you can rename it to what every you want.

<?php
/*
Template Name: Archives
*/
?>

This tells WordPress this file is a page template called Archives. Now we are ready to move on.

Monthly Archives

Now install the plugin SRG Clean Archives and activate it then choose the correct setting in its setting panel in WordPress’ admin panel. Next add this to our template file we just made.

<div class="archives-type">
<h2>Archives by Month:</h2>
<ul>
<?php if (function_exists('srg_clean_archives')) { srg_clean_archives(); } ?>
</ul>
</div>

This creates a div to hold the monthly archives in and then gives it a header of Archives by Month and finally calls the plugin to create a list of the posts.

Archives by Tags

Now we simple copy and past in this below,

<div class="archives-type">
<h2>Archives by Tag:</h2>
<?php wp_tag_cloud('smallest=8&largest=22'); ?>
</div>

Again it creates a div to contain the tags the gives it a header of Archives by Tag. Then we have a WordPress tag that summons a tag cloud and inside that we limit the min size font to 8 and max size to 22, you can adjust sizes to suit your theme.

Archives by Categories

Again this is a simple cut and past job,

<div class="archives-type">
<h2>Archives by Category:</h2>
<ul id="category-centre">
<?php wp_list_categories('title_li='); ?>
<div class="clear"></div>
</ul>
</div>

Here we have a containing div and a header called Archives by category. Then we call WordPress for a list of the categories and tell it to exclude the title categories from the list.

Conclusion

That was simple. Depending on what theme you have you may need to remove certain thing from the copy of the index.php. Some themes already have a archives.php not be confused with archive.php. You can style this however you like but if you just want to see the whole code I am offering my template and the CSS for it as a download here. [download#5#size#nohits]