Creating Helpful and Effective WordPress Archives87
One of the most important elements of your blog, is the content that you painstakingly put together to gain readers and keep the online masses surfing your waves. So why do so many bloggers not take the extra time and give more attention to their archives?
Afterall, without an easy to navigate archive section, then all of that great content that you crafted will become lost in the backpages of your post progression as you continue to crank out the content. It seems that once a post has served its initial use for us, that we carelessly discard it to the forgotten areas for the post to die, rather than institute an accessible archive that will allow those past posts to continue to deliver the punch you packed within.
Our archives allow for an overall easier experience for our readers, by giving them simple access to the content they are looking for. Or more to the point, the information that they do not know they are looking for.
What I mean by that, is this. On occasion, we have users come to our site without a specific target in mind, they are simply browsing for interesting reads. By setting up a thorough collection of your posts, those browsers will have a much easier time surfing for a destination among your archives, keeping the reader engaged and skimming through the content that could have easily fallen through the cracks.
So in this post, I am going to offer some pointers on creating a quality archive section for your blog that will serve as an inspired homage to the awesome content that it contains.
Creating a Template
The first thing you will need to do is to create a WordPress Page Template for your archives page. Here we’ll be creating archives.php in our wordpress theme folder.
So here’s the code we are going to start with, then I am going to give you some options to actually customize the page the way you want it.
NOTE: Since the Template Name is Archives, the page must be named archives.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php /* Template Name: Archives */ ?> <?php get_header(); ?> <div id="archives"> This is where we will actually be building the archives page. </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Posts by Date
While listing archives by date isn’t usually that helpful for finding a particular post or topic, it is a good way to establish your blog (remember that longevity = reader confidence). I recommend simply listing these archives by month to conserve space.
The following code will list the archives by month with no limit to the number of months it will display.
<?php wp_get_archives(); ?>
The following code lists the archives by month displaying only the past 12 months.
<?php wp_get_archives('type=monthly&limit=12'); ?>
You can set the type and limit to whatever your preference is. You can find more information about your options for parameter settings at the WordPress Codex Get Archives Page.
Posts by Category
This will be the most important section of your archives since most readers are not looking for a particular date but for a specific topic.
If you just want to generate a list of your categories use the following code.
<?php wp_list_categories(); ?>
If you would like to exclude certain categories (for example, blog updates) use this code. In this example, categories 10 and 12 will be excluded. To find the id for the category you want to exclude, go to your admin area and go to Posts > Categories. Right click on the category you want to exclude and go to Properties. The category ID number will be at the very end of the address line.
<?php wp_list_categories('exclude=10,12'); ?>
If you would like to show posts from each category, a great plugin that I use on Arbenting is Latest Post from each Category. With this plugin you can choose how many posts from each category you would like to display including the option to list every post from each category.
Most Popular Posts
It is always helpful to direct your visitors to your most popular posts because the content has proven to connect with a range of people. For this you will need the WordPress Popular Posts Plugin.
Then place the following code wherever you want to display your most popular posts. This default will have an h3 header ‘Popular Posts’ and will list 5 posts via their linked titles.
<?php if (function_exists('WPPP_show_popular_posts')) WPPP_show_popular_posts(); ?>
You can also alter these parameters with the options listed at the plugin’s FAQ page.
For example, the following code will have the h4 header ‘Our Most Popular Articles’ and will list 10 posts via linked titles as well as the number of views the post has received.
<?php WPPP_show_popular_posts( "title=<h4>Our Most Popular Articles</h4>&number=10&format=<a href='%post_permalink%' title='%post_title_attribute%'>%post_title% (%post_views% views)</a>" );?>
Most Commented Posts
Highlighting your most commented posts will direct your readers to the most active discussions on your blog, sparking more interaction with your audience which is always beneficial in building a strong readership.
First, you will need to install the Most Commented plugin.
Then insert this code wherever you would like the posts listed. This will show the 5 most commented posts on your blog. You can also alter this number to however many articles you would like to display.
<?php mdv_most_commented(5); ?>
Highlight Your Favorite Posts
If highlighting posts that are your personal favorites is a route you want to go, you will need to create a category titled something like Favorites, and then add all of the posts you want listed here into that category. Using the following code will list all posts in your ‘Favorites’ category.
1 2 3 4
<?php $my_query = new WP_Query('category_name=Favorites'); ?> <?php while (have_posts()) : the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> <?php endwhile;?>
A Search Box
And just in case the reader still does not find what they are looking for on the page, it is nice to provide them with a search box.
If your theme doesn’t already have a searchform.php file, you will need to create it. Simply paste the following code into a new text file and save it as searchform.php in your theme folder.
1 2 3 4 5 6 7
<form id="searchform" method="get" action="/index.php"> <div> <input type="text" name="s" id="s" size="15" /><br /> <input type="submit" value="Search" /> </div> </form> </li>
Then, paste the following code wherever you want the search box to appear in your theme.
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
So, here is our final archives page template. Obviously you will need to create some styling elements to style the page to match your client’s theme.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
<?php /* Template Name: Archives */ ?> <?php get_header(); ?> <div id="archives"> <h3>Monthly Archives</h3> <?php wp_get_archives(); ?> <h3>Archives by Category</h3> <?php wp_list_categories(); ?> <?php WPPP_show_popular_posts( "title=Posts by Popularity&number=5&format=<a href='%post_permalink%' title='%post_title_attribute%'>%post_title% (%post_views% views)</a>" ); ?> <h3>Most Commented Posts</h3> <?php mdv_most_commented(5); ?> <h3>My Favorite Posts</h3> <?php $my_query = new WP_Query('category_name=Favorites'); ?> <?php while (have_posts()) : the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> <?php endwhile;?> <h3>Search the Blog</h3> <?php include (TEMPLATEPATH . '/searchform.php'); ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Now that you have the template complete, upload it to your theme folder, log in to wordpress admin and create a new page. In the right hand column you will see Template listed under Attributes. Choose the Archives page, give the page a title and simply publish.
What have you done with your archives page? Feel free to show off links in the comments!
Enjoy this post? You should follow me on Twitter!