fbpx
2

How to Create an Archives Page For Your WordPress Blog

Last modified on 2nd February, 2007

You may have noticed that my sidebar is now shorter and less cluttered then it was previously. I’ve removed the Categories and Monthly Archives sections and moved them into a new page which I called Archives.

There are several ways to do this and once of which is explained at WordPress.org.

Their suggestion involves creating a new template page called archives.php, customizing the archive template and setting up redirects with your .htaccess file.

Perhaps it’s a more complete way of doing this but some people especially newbies may find it a little complicated or it involved too much work.

So I came up with a more straight forward solution. I must warn you though that I am not a PHP programmer, my solution is not perfect but at least it gets the job done.

To achieve my goal, I needed to run some PHP code on the WordPress page and a plugin called PHPExec helped me to do this. Note that if you are using WordPress 2.0.x you’ll need to use the patched version to make this works.

Also I haven’t tested this with WordPress 2.1 so do it at your own risk if you decide to install it on that version.

Here’s what you have to do.

 

1. Install PHPExec and activate the plugin.

2. Create a page (not a post) as you normally would from you WordPress control panel.

3. Cut your Categories code section from your sidebar and paste it onto the new page. My code originally looked something like this.

 

<h2><?php _e('Categories'); ?></h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=1&children=1'); ?>
</ul><?php $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories");
foreach ($link_cats as $link_cat)
?>

 

4. Then edit the code, enclose it with the <phpcode></phpcode> tags so that the PHP code can run on the page. The resulting code looks like the followings:

 

<phpcode><?php
global $wpdb;
echo "<h2>";
_e('Browse By Categories');
echo "</h2><ul>";
wp_list_cats('sort_column=name&optioncount=1&hierarchical=1&children=1');
echo "</ul>";
$link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories");
foreach ($link_cats as $link_cat);
?></phpcode>

 

Note that you need to declare global $wpdb; at the begginning of your code otherwise you’ll get an error.

5. Click Save and you are done!

With this technique, you can easily add other archive formats such as archive by month or your top 15 post etc.

Anyway, if you have suggestions on how I can improve this, please leave your comment.

update: I’ve upgraded to WordPress 2.1 and my Archives page works fine, so PHPExec should be compatible with WordPress 2.1

Victor
 

An engineer by training, Victor has been working full-time online as an Internet marketer, a programmer and an app developer since 2001. He has been blogging at Sabahan.com since 2006 sharing his experience and teaching people how to make money online. Click here to join his private Facebook Group for bloggers.

  • Lorelle says:

    You might want to offer examples for WordPress 2.1 users using the new wp_list_categories() template tag. wp_list_cats() has been deprecated.

    Good example of how to customize your archives page, as well as a good example of a site map. Thanks.

  • ShaolinTiger says:

    Quite cool, still prefer my separate archive and popular pages tho 🙂

  • >
    Scroll Up

    Sign Up Below... For Tips and Tools to Help You Build a Better Blog

    >> Sign Up Now and get access to:


    • chevron-circle-right
      The exact methods I use to make money
    • chevron-circle-right
      Resources to increase traffic to your blog
    • chevron-circle-right
      The latest updates from Sabahan.com

    We hate spam. Unsubscribe anytime.

    arrow-down
    0 Shares
    Pin
    Share
    Tweet
    Share