diff --git a/wp-blog-header.php b/wp-blog-header.php index 07234917b..6d6433a4b 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -167,6 +167,7 @@ if ((empty($cat)) || ($cat == 'all') || ($cat == '0')) { if ('' != $category_name) { $category_name = preg_replace('|[^a-z0-9-/]|', '', $category_name); + $tables = ", $tablepost2cat, $tablecategories"; $join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) "; $whichcat = " AND (category_nicename = '$category_name') "; $cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'"); @@ -319,6 +320,25 @@ if ($preview) { // echo $request; $posts = $wpdb->get_results($request); + +// Get the categories for all the posts +foreach ($posts as $post) { + $post_id_list[] = $post->ID; +} +$post_id_list = implode(',', $post_id_list); + +$dogs = $wpdb->get_results("SELECT DISTINCT + ID, category_id, cat_name, category_nicename, category_description + FROM $tablecategories, $tablepost2cat, $tableposts + WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)"); + +foreach ($dogs as $catt) { + $category_cache[$catt->ID][] = $catt; +} + +// Do the same for comment numbers + + if (1 == count($posts)) { if ($p || $name) { $more = 1; diff --git a/wp-includes/template-functions.php b/wp-includes/template-functions.php index 4967d6d1d..c314d156d 100644 --- a/wp-includes/template-functions.php +++ b/wp-includes/template-functions.php @@ -1332,14 +1332,18 @@ function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Ne /***** Category tags *****/ function get_the_category() { - global $post, $tablecategories, $tablepost2cat, $wpdb; - $categories = $wpdb->get_results(" - SELECT category_id, cat_name, category_nicename, category_description - FROM $tablecategories, $tablepost2cat - WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID - "); - - return $categories; + global $post, $tablecategories, $tablepost2cat, $wpdb, $category_cache; + if ($category_cache[$post->ID]) { + return $category_cache[$post->ID]; + } else { + $categories = $wpdb->get_results(" + SELECT category_id, cat_name, category_nicename, category_description + FROM $tablecategories, $tablepost2cat + WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID + "); + + return $categories; + } } function get_category_link($echo = false, $category_id, $category_nicename) {