Added last date, post count, and hide empty mods to list_cats.

git-svn-id: http://svn.automattic.com/wordpress/trunk@259 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
mikelittle 2003-07-19 22:55:18 +00:00
parent 3d1da58e9e
commit 44198a4506
1 changed files with 33 additions and 10 deletions

View File

@ -860,27 +860,50 @@ function dropdown_cats($optionall = 1, $all = 'All') {
} }
// out of the b2 loop // out of the b2 loop
function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = 'blah', $list = true) { function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc',
global $tablecategories, $querycount, $wpdb; $file = 'blah', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1) {
global $tablecategories, $tableposts, $querycount, $wpdb;
global $pagenow; global $pagenow;
global $querystring_start, $querystring_equal, $querystring_separator; global $querystring_start, $querystring_equal, $querystring_separator;
$file = ($file == 'blah') ? $pagenow : $file; if (($file == 'blah') || ($file == '')) {
$file = $pagenow;
}
$sort_column = 'cat_'.$sort_column; $sort_column = 'cat_'.$sort_column;
$categories = $wpdb->get_results("SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order");
$query = " SELECT cat_ID, cat_name,";
$query .= " COUNT($tableposts.ID) AS cat_count,";
$query .= " DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth";
$query .= " FROM $tablecategories LEFT JOIN $tableposts ON cat_ID = post_category";
$query .= " WHERE cat_ID > 0 ";
$query .= " GROUP BY post_category ";
if (intval($hide_empty) == 1) {
$query .= " HAVING cat_count > 0";
}
$query .= " ORDER BY $sort_column $sort_order, post_date DESC";
$categories = $wpdb->get_results($query);
++$querycount; ++$querycount;
if (intval($optionall) == 1) { if (intval($optionall) == 1) {
$all = apply_filters('list_cats', $all); $all = apply_filters('list_cats', $all);
if ($list) echo "\n\t<li><a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a></li>"; $link = "<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a>";
else echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a><br />\n"; if ($list) echo "\n\t<li>$link</li>";
else echo "\t$link<br />\n";
} }
foreach ($categories as $category) { foreach ($categories as $category) {
$cat_name = apply_filters('list_cats', $category->cat_name); $cat_name = apply_filters('list_cats', $category->cat_name);
$link = "<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$category->cat_ID.'">';
$link .= stripslashes($cat_name)."</a>";
if (intval($optioncount) == 1) {
$link .= "&nbsp;&nbsp;(".$category->cat_count.")";
}
if (intval($optiondates) == 1) {
$link .= "&nbsp;&nbsp;".$category->lastday."/".$category->lastmonth."";
}
$link .= "</a>";
if ($list) { if ($list) {
echo "\n\t<li><a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$category->cat_ID.'">'; echo "\n\t<li>$link</li>";
echo stripslashes($cat_name)."</a></li>";
} else { } else {
echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$category->cat_ID.'">'; echo "\t$link<br />\n";
echo stripslashes($cat_name)."</a><br />\n";
} }
} }
} }