Changeset 5529 for trunk/wp-includes/category.php
- Timestamp:
- 05/23/2007 06:07:53 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/category.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/category.php
r5528 r5529 103 103 } 104 104 105 //106 // Private107 //108 109 function &_get_cat_children($category_id, $categories) {110 if ( empty($categories) )111 return array();112 113 $category_list = array();114 $has_children = _get_category_hierarchy();115 116 if ( ( 0 != $category_id ) && ! isset($has_children[$category_id]) )117 return array();118 119 foreach ( $categories as $category ) {120 if ( $category->cat_ID == $category_id )121 continue;122 123 if ( $category->category_parent == $category_id ) {124 $category_list[] = $category;125 126 if ( !isset($has_children[$category->cat_ID]) )127 continue;128 129 if ( $children = _get_cat_children($category->cat_ID, $categories) )130 $category_list = array_merge($category_list, $children);131 }132 }133 134 return $category_list;135 }136 137 // Recalculates link or post counts by including items from child categories138 // Assumes all relevant children are already in the $categories argument139 function _pad_category_counts($type, &$categories) {140 global $wpdb;141 142 // Set up some useful arrays143 foreach ( $categories as $key => $cat ) {144 $cats[$cat->cat_ID] = & $categories[$key];145 $cat_IDs[] = $cat->cat_ID;146 }147 148 // Get the relevant post2cat or link2cat records and stick them in a lookup table149 if ( $type == 'post' ) {150 $results = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat LEFT JOIN $wpdb->posts ON post_id = ID WHERE category_id IN (".join(',', $cat_IDs).") AND post_type = 'post' AND post_status = 'publish'");151 foreach ( $results as $row )152 ++$cat_items[$row->category_id][$row->post_id];153 } else {154 $results = $wpdb->get_results("SELECT $wpdb->link2cat.link_id, category_id FROM $wpdb->link2cat LEFT JOIN $wpdb->links USING (link_id) WHERE category_id IN (".join(',', $cat_IDs).") AND link_visible = 'Y'");155 foreach ( $results as $row )156 ++$cat_items[$row->category_id][$row->link_id];157 }158 159 // Touch every ancestor's lookup row for each post in each category160 foreach ( $cat_IDs as $cat_ID ) {161 $child = $cat_ID;162 while ( $parent = $cats[$child]->category_parent ) {163 if ( !empty($cat_items[$cat_ID]) )164 foreach ( $cat_items[$cat_ID] as $item_id => $touches )165 ++$cat_items[$parent][$item_id];166 $child = $parent;167 }168 }169 170 // Transfer the touched cells171 foreach ( (array) $cat_items as $id => $items )172 if ( isset($cats[$id]) )173 $cats[$id]->{'link' == $type ? 'link_count' : 'category_count'} = count($items);174 }175 176 function _get_category_hierarchy() {177 return _get_term_hierarchy('category');178 }179 180 105 // Tags 181 106
Note: See TracChangeset
for help on using the changeset viewer.