<?php
/*
Plugin Name: Hicksdesign Style Archives
Version: 0.4
Plugin URI: http://www.lattimore.id.au/projects/
Author: Alistair Lattimore
Author URI: http://www.lattimore.id.au
Description: Displays a definition list of posts, in the same style as http://www.hicksdesign.co.uk/archive/.
*/

function arl_hicksdesign_archives()
{
    global 
$wpdb;
    
$previous "";

    
$sql "SELECT post_date,";
    
$sql .= " DATE_FORMAT(post_date, '%d') AS day,";
    
$sql .= " DATE_FORMAT(post_date, '%m') AS month,";
    
$sql .= " DATE_FORMAT(post_date, '%Y') AS year,";
    
$sql .= " DATE_FORMAT(post_date, '%M %Y') AS monthyear,";
    
$sql .= " id,";
    
$sql .= " post_title,";
    
$sql .= " guid ";
    
$sql .= "FROM $wpdb->posts ";
    
$sql .= "WHERE post_status = 'publish'";
    
$sql .= " AND post_type = 'post' ";
    
$sql .= "ORDER BY post_date DESC";
    
    
$posts $wpdb->get_results($sql);

    print 
"<dl>\n";
    
    if (!empty(
$posts))
    {
        foreach (
$posts as $post)
        {
            if (
$post->monthyear != $previous)
            {
                
$previous $post->monthyear
                print 
'<dt><a href="' get_month_link($post->year$post->month) . '">' $post->monthyear '</a></dt>';
                print 
"\n";
            }

            print 
'<dd><span>' $post->day ':</span> <a href="' get_permalink($post->id) . '">' $post->post_title '</a></dd>';
            print 
"\n";
        }
    }
    else
    {
        print 
"<dt>Posts</dt>\n";
        print 
"<dd>None available</dd>\n";
    }

    print 
"</dl>\n";

    return;
}
?>