<?php
/*
categories [-r] [search_term]
@@
Usage: $0
Switches: 
	r: reverse order
Displays a list of categories for the blog. The list is clickable, i.e. if a category name is clicked a list of posts tagged with that category is shown.
@@
*/
		$w='';
		$d='ASC';
		if(array_search('r',$switches)){
			$d='DESC';
		}
		if($params){
			$w="WHERE `cat_name` LIKE '%".mysql_real_escape_string($params)."%'";
		}
		$q="SELECT `cat_ID`,`cat_name`, `category_count` 
			FROM `".$wpdb->categories."` $w 
			ORDER BY `cat_name` $d";
		$r=mysql_query($q);
		e('<table>');
		for($i=0;$i<mysql_num_rows($r);$i++){
			list($id,$name,$count)=mysql_fetch_row($r);
			e("<tr onclick=\"showcat('$id')\"><td>$id</td><td class=\"linky\">$name</td><td>($count)</td></tr>");
			
		}
		e('</table>');
?>
