Changeset 8323
- Timestamp:
- 03/17/2007 01:28:26 AM (19 years ago)
- File:
-
- 1 edited
-
gengo/trunk/gengo/gengo.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gengo/trunk/gengo/gengo.php
r8314 r8323 651 651 652 652 // Called from wp_list_categories. 653 function get_categories($categories, $arguments) {654 global $wpdb;653 function get_categories($categories, $arguments) { 654 global $wpdb; 655 655 656 656 if (('post' != $arguments['type']) || !$categories) return $categories; … … 660 660 } 661 661 $category_ids = implode(',', $category_ids); 662 662 663 $viewable_codes = explode(GENGO_LANGUAGE_DIVIDER, $this->viewable_code_string); 663 664 foreach ($viewable_codes as $viewable_code) $ids[] = $this->codes2ids[$viewable_code]; 664 665 $language_ids = implode(',', $ids); 665 666 if ($language_ids) { 666 $categories = $wpdb->get_results("SELECT c.*, COUNT(DISTINCT (CASE WHEN translation_group > 0 THEN -translation_group ELSE p2l.post_id END)) as category_count FROM $this->post2lang_table p2l INNER JOIN $wpdb->post2cat p2c ON p2c.post_id = p2l.post_id INNER JOIN $wpdb->posts p ON p2l.post_id = p.ID INNER JOIN $wpdb->categories AS c ON p2c.category_id = c.cat_ID WHERE p2l.language_id IN ($language_ids) AND p2c.category_id IN ($category_ids) AND p.post_type = 'post' AND p.post_status = 'publish' GROUP BY c.cat_ID $sort_column $sort_order"); 667 $counted_categories = $wpdb->get_results("SELECT c.cat_ID, p.post_type, COUNT(DISTINCT (CASE WHEN translation_group > 0 THEN -translation_group ELSE p2l.post_id END)) as category_count FROM $this->post2lang_table p2l INNER JOIN $wpdb->post2cat p2c ON p2c.post_id = p2l.post_id INNER JOIN $wpdb->posts p ON p2l.post_id = p.ID INNER JOIN $wpdb->categories AS c ON p2c.category_id = c.cat_ID WHERE p2l.language_id IN ($language_ids) AND p2c.category_id IN ($category_ids) AND p.post_status = 'publish' GROUP BY c.cat_ID, p.post_type $sort_column $sort_order"); 668 669 foreach ($counted_categories as $counted_category) { 670 $hashed_counts[$counted_category->post_type][$counted_category->cat_ID] = $counted_category->category_count; 671 } 672 $post_types = array_keys($hashed_counts); 673 674 foreach ($categories as $cat) { 675 foreach ($post_types as $post_type) { 676 $count_slot = ('post' == $post_type) ? 'category_count' : 'category_' . $post_type . 'count'; 677 $cat->$count_slot = $hashed_counts[$post_type][$cat->cat_ID]; 678 } 679 } 680 681 if ($arguments['hide_empty'] || $arguments['pad_counts']) { 682 $protected = -1; 683 $pad = array(); 684 $keys = array_reverse(array_keys($categories)); 685 foreach ($keys as $k) { 686 $cat = $categories[$k]; 687 if ($cat->category_count || ($cat->cat_ID == $protected)) { 688 if ($arguments['hierarchical']) { 689 $protected = $cat->category_parent; 690 } 691 if ($arguments['pad_counts']) { 692 // Known bug: if a post belongs to a category and its parent, counted twice. Not worth the trouble. 693 $cat->category_count += $pad[$cat->cat_ID]; 694 if ($cat->category_parent) { 695 $pad[$cat->category_parent] += $cat->category_count; 696 } 697 } 698 } elseif ($arguments['hide_empty']) { 699 unset($categories[$k]); 700 } 701 } 702 } 667 703 } 668 704 return $categories; 669 }705 } 670 706 671 707 function post_comments_feed_link($url) { … … 1922 1958 /* 1923 1959 1924 Fatal error get_currentuserinfo()1925 categories from MAP.1926 in_category().1927 1928 1960 0.91: 1929 1961 ----- 1930 1962 1963 1964 1931 1965 autochange the spellchecker if possible... 1932 1966 move the caching into the_posts()
Note: See TracChangeset
for help on using the changeset viewer.