last_cats fix from TheJason.

git-svn-id: https://develop.svn.wordpress.org/trunk@797 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2004-01-26 20:34:14 +00:00
parent 0b88590afe
commit 3ca7dad5d1
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"; 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) { 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 $tablecategories, $tableposts, $tablepost2cat, $wpdb;
global $pagenow, $siteurl, $blogfilename; global $pagenow, $siteurl, $blogfilename;
global $querystring_start, $querystring_equal, $querystring_separator; global $querystring_start, $querystring_equal, $querystring_separator;
// Optiondates does not currently work // Optiondates now works
if ('' == $file) { if ('' == $file) {
$file = "$siteurl/$blogfilename"; $file = "$siteurl/$blogfilename";
} }
@ -1503,7 +1503,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
$categories = $wpdb->get_results($query); $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, $cat_counts = $wpdb->get_results(" SELECT cat_ID,
COUNT($tablepost2cat.post_id) AS cat_count COUNT($tablepost2cat.post_id) AS cat_count
FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id) 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) { if (intval($optiondates) == 1) {
$link .= '&nbsp;('.$category->cat_count.')'; $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) { if (!$categories) {
@ -1528,22 +1536,21 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
} }
foreach ($categories as $category) { 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).'" '; $link = '<a href="'.get_category_link(0, $category->cat_ID, $category->category_nicename).'" ';
if ($use_desc_for_title == 0 || empty($category->category_description)) { if ($use_desc_for_title == 0 || empty($category->category_description)) {
$link .= 'title="View all posts filed under ' . htmlspecialchars($category->cat_name) . '"'; $link .= 'title="View all posts filed under ' . htmlspecialchars($category->cat_name) . '"';
} } else {
else {
$link .= 'title="' . htmlspecialchars($category->category_description) . '"'; $link .= 'title="' . htmlspecialchars($category->category_description) . '"';
} }
$link .= '>'; $link .= '>';
$link .= stripslashes($category->cat_name).'</a>'; $link .= stripslashes($category->cat_name).'</a>';
if (intval($optioncount) == 1) { if (intval($optioncount) == 1) {
$link .= ' ('.$category_posts["$category->cat_ID"].')'; $link .= ' ('.intval($category_posts["$category->cat_ID"]).')';
} }
if (intval($optiondates) == 1) { 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) { if ($list) {
echo "\t<li>$link</li>\n"; echo "\t<li>$link</li>\n";
} else { } else {
@ -1649,9 +1656,8 @@ function comment_author() {
$author = apply_filters('comment_auther', $author); $author = apply_filters('comment_auther', $author);
$author = convert_chars($author); $author = convert_chars($author);
if (!empty($author)) { if (!empty($author)) {
echo $comment->comment_author; echo $author;
} } else {
else {
echo "Anonymous"; echo "Anonymous";
} }
} }