Changeset 6588 for trunk/wp-admin/includes/template.php
- Timestamp:
- 01/10/2008 09:39:35 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/template.php
r6570 r6588 119 119 } 120 120 121 function get_nested_categories( $default = 0, $parent = 0 ) {121 function wp_set_checked_post_categories( $default = 0 ) { 122 122 global $post_ID, $checked_categories; 123 123 … … 135 135 } 136 136 137 $cats = get_categories("parent=$parent&hide_empty=0&fields=ids"); 138 139 $result = array (); 140 if ( is_array( $cats ) ) { 141 foreach ( $cats as $cat) { 142 $result[$cat]['children'] = get_nested_categories( $default, $cat); 143 $result[$cat]['cat_ID'] = $cat; 144 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 145 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); 137 } 138 function get_nested_categories( $default = 0, $parent = 0 ) { 139 global $checked_categories; 140 141 wp_set_checked_post_categories( $default = 0 ); 142 143 if ( is_object($parent) ) { // Hack: if passed a category object, will return nested cats with parent as root 144 $root = array( 145 'children' => get_nested_categories( $default, $parent->term_id ), 146 'cat_ID' => $parent->term_id, 147 'checked' => isset($parent->_is_checked) && $parent->_is_checked, 148 'cat_name' => get_the_category_by_ID( $parent->term_id ) 149 ); 150 $result = array( $parent->term_id => $root ); 151 } else { 152 $parent = (int) $parent; 153 154 $cats = get_categories("parent=$parent&hide_empty=0&fields=ids"); 155 156 $result = array(); 157 if ( is_array( $cats ) ) { 158 foreach ( $cats as $cat ) { 159 $result[$cat]['children'] = get_nested_categories( $default, $cat ); 160 $result[$cat]['cat_ID'] = $cat; 161 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 162 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat ); 163 } 146 164 } 147 165 } … … 166 184 } 167 185 168 function dropdown_categories( $default = 0 ) { 169 write_nested_categories( get_nested_categories( $default) ); 186 function dropdown_categories( $default = 0, $parent = 0 ) { 187 write_nested_categories( get_nested_categories( $default, $parent ) ); 188 } 189 190 function wp_popular_categories_checklist( $default = 0, $number = 10 ) { 191 global $checked_categories; 192 193 wp_set_checked_post_categories( $default ); 194 195 $categories = get_categories( array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) ); 196 197 foreach ( (array) $categories as $category ) { 198 $id = "popular-category-$category->term_id"; 199 $checked = in_array( $category->term_id, $checked_categories ) ? ' checked="checked"' : ''; 200 ?> 201 202 <li id="<?php echo $id; ?>"> 203 <label class="selectit" for="in-<?php echo $id; ?>"> 204 <input id="in-<?php echo $id; ?>" type="checkbox" name="post_category[]" value="<?php echo (int) $category->term_id; ?>"<?php echo $checked; ?> /> 205 <?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?> 206 </label> 207 </li> 208 209 <?php 210 } 170 211 } 171 212
Note: See TracChangeset
for help on using the changeset viewer.