WordPress Archive Lists

One thing I haven’t become involved with is writing plugins for WordPress but I have been looking at ways to make my blog more efficient.

I tried out a tag system back in October but found that it generated too many tags and often irrelevant tags so finally scrapped it in favour of the plugins from Ultimate Tag Warrior produced by fellow kiwi Christine Davis (who I don’t actually know ;)). Her system allowed me to produce a “Tag Cloud” which is pretty cool.

I haven’t totally got my head around the custom tags page with url rewriting but for now I’m happy with urls like /index.php?tag=kiwi and I’ve learnt a little about templates.

So when I posted some info about the UTW plugin at DigitalPoint one of the members asked about Category Archives and gave a new plugin to use. I took a look and couldn’t quite work out how to use it, so took the lessons from UTW and applied them!

SKArchive

I didn’t want to replace the default pages when I click on the category name, or change the core template so I’m calling this “SKArchive”. First, check out my wordpress archive page.

  1. Create a “skarchive.php” in your template folder (contents below) and upload
  2. In the Admin control panel create a new page and change the template to SKArchive. Save.
  3. Now, view your blog and it should all be there. Tweak as necessary.

The Code
[php]< ?php
/*
Template Name: SKArchive
*/
?>
< ?php get_header(); ?>
< ?php

/**

  • @return string
  • @param int $catID
  • @desc returns a list of posts for a category

*/
function wp_cat_posts( $catID )
{
global $wpdb;
$output = ”;

$get_posts_in_cat = “SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_title,
{$wpdb->post2cat}.post_id, {$wpdb->post2cat}.category_id
FROM `{$wpdb->posts}`, `{$wpdb->post2cat}`
WHERE {$wpdb->posts}.ID = {$wpdb->post2cat}.post_ID
AND {$wpdb->post2cat}.category_id = ‘$catID’
AND {$wpdb->posts}.post_status = ‘publish’
ORDER BY {$wpdb->posts}.post_date desc “;

$get_posts_in_cat_result = mysql_query($get_posts_in_cat);

if (mysql_num_rows($get_posts_in_cat_result) > 0)
{
$output = ‘

    ‘;
    while ($posts_in_cat_row = mysql_fetch_assoc($get_posts_in_cat_result))
    {
    $post_title = $posts_in_cat_row['post_title'];
    $postID = $posts_in_cat_row['ID'];

    $output .= “

  • {$post_title}
  • \n”;
    }
    $output .= ‘

‘;
}
return $output;
}//wp_cat_posts

global $wpdb;

$get_cat = “SELECT *
FROM `{$wpdb->categories}`
order by cat_name”;

$get_cat_result = mysql_query($get_cat);

while ($cat_row = mysql_fetch_object($get_cat_result))
{
$link = ‘