last_cats fix from TheJason.

git-svn-id: http://svn.automattic.com/wordpress/trunk@797 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2004-01-26 20:34:14 +00:00
parent e9c7715b9a
commit 996ba79f93
1 changed files with 64 additions and 58 deletions

View File

@ -1484,12 +1484,12 @@ function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_
echo "</select>\n";
}
// out of the WordPress loop
// Out of the WordPress loop
function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 0) {
global $tablecategories, $tableposts, $tablepost2cat, $wpdb;
global $pagenow, $siteurl, $blogfilename;
global $querystring_start, $querystring_equal, $querystring_separator;
// Optiondates does not currently work
// Optiondates now works
if ('' == $file) {
$file = "$siteurl/$blogfilename";
}
@ -1503,7 +1503,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
$categories = $wpdb->get_results($query);
if (intval($hide_empty) == 1) {
if (intval($hide_empty) == 1 || intval($optioncount) == 1) {
$cat_counts = $wpdb->get_results(" SELECT cat_ID,
COUNT($tablepost2cat.post_id) AS cat_count
FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
@ -1514,8 +1514,16 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
}
}
if (intval($optioncount) == 1) {
$link .= '&nbsp;('.$category->cat_count.')';
if (intval($optiondates) == 1) {
$cat_dates = $wpdb->get_results(" SELECT cat_ID,
DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth
FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
LEFT JOIN $tableposts ON (ID = post_id)
GROUP BY category_id");
foreach ($cat_dates as $cat_date) {
$category_lastday["$cat_date->cat_ID"] = $cat_date->lastday;
$category_lastmonth["$cat_date->cat_ID"] = $cat_date->lastmonth;
}
}
if (!$categories) {
@ -1528,22 +1536,21 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
}
foreach ($categories as $category) {
if (intval($hide_empty) == 0 || $category_posts["$category->cat_ID"] > 0) {
$link = '<a href="'.get_category_link(0, $category->cat_ID, $category->category_nicename).'" ';
if ($use_desc_for_title == 0 || empty($category->category_description)) {
$link .= 'title="View all posts filed under ' . htmlspecialchars($category->cat_name) . '"';
}
else {
} else {
$link .= 'title="' . htmlspecialchars($category->category_description) . '"';
}
$link .= '>';
$link .= stripslashes($category->cat_name).'</a>';
if (intval($optioncount) == 1) {
$link .= ' ('.$category_posts["$category->cat_ID"].')';
$link .= ' ('.intval($category_posts["$category->cat_ID"]).')';
}
if (intval($optiondates) == 1) {
$link .= ' '.$category->lastday.'/'.$category->lastmonth;
$link .= ' '.$category_lastday["$category->cat_ID"].'/'.$category_lastmonth["$category->cat_ID"];
}
if (!$hide_empty || $category_posts[$category->cat_ID]) {
if ($list) {
echo "\t<li>$link</li>\n";
} else {
@ -1649,9 +1656,8 @@ function comment_author() {
$author = apply_filters('comment_auther', $author);
$author = convert_chars($author);
if (!empty($author)) {
echo $comment->comment_author;
}
else {
echo $author;
} else {
echo "Anonymous";
}
}