How To *Easily* Make WordPress Archives That Rock – Smashing WordPress Tutorials #1
Today’s Sunday, and here’s a nifty little tutorial for you to enjoy, while you relax out. So, enjoy! And oh, this post is Part 1 of Smashing WordPress Tutorials. The next tutorial will be on automatically updating pages. Subscribe to the RSS feed to be the first to know of new content!
The archives of your blog are like a museum, which store all your posts, for anyone to view. An archives page is an essential part of a blog, so if you don’t have one, you should consider creating one. If you don’t know how to, you’ve come to the right place!
Define Your Aims First
The first thing to do is to plan out your archives. What are you going to show on the archives page, and how? Here’s a possible combination that is simple yet effective, which I also use on PuttingBlogsFirst
- A monthly(or yearly) list. Visit the PBF archives for example.
- ALL the posts ever on your blog.
- Optional: A list of all the categories. I don’t use this, because the list of categories is already present in the sidebar. *shrug*
Now that we’ve got our goals defined, let’s start building!
The Archives Page
Before we actually start building our archives, we want an archives.php file.
We’ll also have to create a Page in WordPress for this. More on this later.
Now, I’m assuming you already have a barebones master template like similar to this(save it as archives.php):
<div id=”container”>
<?php if (have_posts()) : ?>
<div id=”content”>
</div>
<?php endif; ?>
</div>
<?php get_sidebar();?>
<?php get_footer();?>
Now, in this case, all my code would go between <div id="content"> and
</div>. Find the place in your theme.
The WordPress Page
None of this will work unless you create a WordPress Page for your archives. So, first, add these lines to the very top of your archives.php page:
/*
Template Name: Archives
*/
?>
Now, go to the Write Page option in your WordPress admin, and name the page something descriptive, such as ‘Archives’. Do not write anything in the content area.
Next, scroll down to the Page Templates option, and select the ‘Archives’ one. And then save the page, and enjoy this tutorial!
The Code Itself
First, we have to list the archives ordered by month. For that, we use the wp_get_archives() template tag. Here is the complete code(with some organization):
<ul class=”archivelist”>
<?php wp_get_archives(‘type=monthly&show_post_count=1′) ?>
</ul>
First, I put in a level 3 heading, telling people that these are the monthly archives. The type is set to monthly and it shows the archives in monthly format. The show_post_count parameter is set to 1(ON), which means that the number of posts in that particular month are shown in brackets beside the month name.
I’ve also enclosed this tag in an unordered list (<ul>), because this tag generates list items (<li>) without being enclosed in a(at least when used like this). You can improve the look of these archives even further using CSS and divs, but that’s another story
TIP 1: To display the archives ordered by year, instead of months, change the type parameter to yearly. For a daily listing, change it to daily. For a weekly listing, change it to weekly
Showing ALL Posts
Now, we show all the posts ever, on your blog. There are several template tags here to do the job, but I’m going to be using the same one as the above, wp_get_archives(), since it’s very easy to use. So, here’s the code to use:
<ul class=”archivelist”>
<?php wp_get_archives(‘type=postbypost’);?>
</ul>
Again, I use a level 3 heading to tell the users what this big list is all about. Again I enclose the tag in an unordered list. The type parameter is set to postbypost, so all posts are displayed by post title, with the most recent one first.
TIP: If you wanted to limit the listing to, say, only the most 20 recent posts, add limit=20 to the paramaters, like so:
And you’re done!
Archives Ordered By Category
Another way to show your archives is to show it by category(like in the sidebar of this blog). The template tag for this job is wp_list_categories(). Here you go:
This will output all the categories there are on your blog. Also, the show_count parameter is set to 1(ON), so this also displays the number posts in ever category next to the category name.
And you’re done!
Some Books You Might Like
If you’re interested in WordPress (I’m sure you are, if you’re reading this post!
), here are some books on the subject. These books are tutorials on the WordPress platform, and teach you various things: from setting up WordPress as your blog, to marketing it. Take it from me, these books are highly recommended (Note: These links are affiliate links.) :
- WordPress for Business Bloggers: Promote and grow your WordPress blog with advanced plug-ins, analytics, advertising, and SEO
- WordPress Entrepreneur: How to Setup, Customize & Use a WordPress Website
- WordPress Complete: A comprehensive, step-by-step guide on how to set up, customize, and market your blog using WordPress
What do You Think?
Try out this and make your archives ROCK!
If you run into any problems, do let me know!
The next tutorial will be on automatically updating pages. Subscribe to the RSS feed to be the first to know of new content!
If you liked this post, consider subscribing to the RSS feed (what's RSS?) to get updates on new blog posts.







This is great! Is it possible to list post-by-post for each month? For example:
August 2008
- Post 3
- Post 2
- Post 1
July 2008
- Post 3
- Post 2
- Post 1
Yes, Can I get the list of posts by month. Even I wanna display posts like that in archive.
Can one also organize a wordpress blog archive not only by a complete post title list and by category, but also by selected post tags?
Here’s why I ask. Perhaps other bloggers, even ones with very different blog subject matter, have a similar issue: I’m starting a cooking blog, in which virtually all posts would be recipes. The least important thing a reader would want to know is what year/month the post was published, which is how blog archives are normally organized. Instead, they will want to browse my blog content in one of three ways and should have the option to do so: by post title (a complete list), by category (in my case by main ingredient), and by selected tag (in my case by appetizer, main course, desert, etc.). I’m really struggling with this and would appreciate any advice you can give.
Oops! and one more thing: having the above presented in a drop-down menu would be pretty darned convenient too, to minimize excessive scrolling by readers.
Can you tell me what the php code searches on to find the archived pages? Is it the date the post/page was created?
yummmy:) thanks to your suggestions , i’d love to comply with your weblog as generally as i can.possess a wonderful day~~
Thanks for the code. I’m creating a new wordpress theme and I have alreday creat my archive.php.There’s one more question I want to ask. If I just want 20 articals in one page, I want apagenavi at the bottom of the page, How can I do that?