<?php
/*
Plugin Name: Tag Cloud
Plugin URI: http://burnfield.com/martin, http://register.intruder.ru/tagcloud
Description: View the categories as a tag cloud. Mainly a simplified version of the TagCloud-plugin by alex-and-r
Author: Martin Str&ouml;m & alex-and-r
Version: 0.2.1
Author URI: http://burnfield.com/martin, http://www.intruder.ru
*/

function tag_cloud($smallest=.8$largest=3.5$unit="em") {
    global 
$wpdb;

    
$query  "
        SELECT cat_name,
        COUNT($wpdb->post2cat.post_id) AS cat_count,
        cat_id
        FROM $wpdb->categories
        INNER JOIN $wpdb->post2cat ON (cat_ID = category_id)
        INNER JOIN $wpdb->posts ON (ID = post_id)
        WHERE ( post_status = 'publish' OR post_status = 'private' )
        GROUP BY category_id"
;

    
$categories $wpdb->get_results($query);

    foreach(
$categories as $cat) {
        
$cats[$cat->cat_name] = $cat->cat_count;
    }

    
ksort($cats);
    
reset($cats);

    
$spread max($cats) - min($cats);
    
    if (
$spread <= 0$spread 1;
    
$fontspread $largest $smallest;
    
    
$fontstep   $spread $fontspread;
    if (
$fontspread <= 0$fontspread 1;

    
$thelist "";

    foreach (
$cats as $catname => $count) {
        
$link '<a href="' get_category_link(0) . $catname '" ';
        
$link .= 'style="font-size: ' . ($smallest + ($count/$fontstep)) . $unit .';" rel="tag">';
        
$link .= $catname '</a>';
        
$thelist .= $link ' ';
    }

    echo 
apply_filters('list_cats'$thelist);
}

?>