diff --git a/b2-include/b2template.functions.php b/b2-include/b2template.functions.php index 1b8a60214..db045e97d 100644 --- a/b2-include/b2template.functions.php +++ b/b2-include/b2template.functions.php @@ -1348,7 +1348,7 @@ function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_ // out of the b2 loop function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = 'blah', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1) { - global $tablecategories, $tableposts, $wpdb; + global $tablecategories, $tableposts, $tablepost2cat, $wpdb; global $pagenow, $siteurl, $blogfilename; global $querystring_start, $querystring_equal, $querystring_separator; if (($file == 'blah') || ($file == '')) { @@ -1356,12 +1356,15 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde } $sort_column = 'cat_'.$sort_column; - $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 "; + $query = " + SELECT cat_ID, cat_name, + COUNT($tablepost2cat.post_id) AS cat_count, + 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) + WHERE cat_ID > 0 + GROUP BY category_id + "; if (intval($hide_empty) == 1) { $query .= " HAVING cat_count > 0"; } @@ -1385,7 +1388,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde foreach ($categories as $category) { $cat_name = apply_filters('list_cats', $category->cat_name); - $link = ''; + $link = ''; $link .= stripslashes($cat_name).''; if (intval($optioncount) == 1) { $link .= '  ('.$category->cat_count.')';