From 523757d3e6a4a1b9775147b80ef15d0c47b428f3 Mon Sep 17 00:00:00 2001 From: michelvaldrighi Date: Wed, 16 Feb 2005 16:06:07 +0000 Subject: [PATCH] getting the list of categories from cat_counts if hide_empty is true, saves one query git-svn-id: https://develop.svn.wordpress.org/trunk@2356 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/template-functions-category.php | 28 ++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/wp-includes/template-functions-category.php b/wp-includes/template-functions-category.php index 1a68794b3e..41686d3eec 100644 --- a/wp-includes/template-functions-category.php +++ b/wp-includes/template-functions-category.php @@ -269,20 +269,27 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde } } - if (intval($categories)==0){ - $sort_column = 'cat_'.$sort_column; + if ($hide_empty) { + $categories = array(); + $extra_fields = 'cat_name, category_nicename, category_description,'; + } else { + if (intval($categories)==0 && !$hide_empty){ + $sort_column = 'cat_'.$sort_column; - $query = " - SELECT cat_ID, cat_name, category_nicename, category_description, category_parent - FROM $wpdb->categories - WHERE cat_ID > 0 $exclusions - ORDER BY $sort_column $sort_order"; + $query = " + SELECT cat_ID, cat_name, category_nicename, category_description, category_parent + FROM $wpdb->categories + WHERE cat_ID > 0 $exclusions + ORDER BY $sort_column $sort_order"; - $categories = $wpdb->get_results($query); + $categories = $wpdb->get_results($query); + } + $extra_fields = ''; } + if (!count($category_posts)) { $now = current_time('mysql', 1); - $cat_counts = $wpdb->get_results(" SELECT cat_ID, + $cat_counts = $wpdb->get_results(" SELECT cat_ID, $extra_fields COUNT($wpdb->post2cat.post_id) AS cat_count FROM $wpdb->categories INNER JOIN $wpdb->post2cat ON (cat_ID = category_id) @@ -294,6 +301,9 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde foreach ($cat_counts as $cat_count) { if (1 != intval($hide_empty) || $cat_count > 0) { $category_posts["$cat_count->cat_ID"] = $cat_count->cat_count; + if ($hide_empty) { + $categories[] = $cat_count; + } } } }