| | 244 | class Walker_Category_Checklist extends Walker { |
| | 245 | var $tree_type = 'category'; |
| | 246 | var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this |
| | 247 | |
| | 248 | function start_lvl($output, $depth, $args) { |
| | 249 | $indent = str_repeat("\t", $depth); |
| | 250 | $output .= "$indent<ul class='children'>\n"; |
| | 251 | return $output; |
| | 252 | } |
| | 253 | |
| | 254 | function end_lvl($output, $depth, $args) { |
| | 255 | $indent = str_repeat("\t", $depth); |
| | 256 | $output .= "$indent</ul>\n"; |
| | 257 | return $output; |
| | 258 | } |
| | 259 | |
| | 260 | function start_el($output, $category, $depth, $args) { |
| | 261 | extract($args); |
| | 262 | |
| | 263 | $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; |
| | 264 | $output .= "\n<li id='category-$category->term_id'$class>" . '<label for="in-category-' . $category->term_id . '" class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category[]" id="in-category-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . wp_specialchars( apply_filters('the_category', $category->name )) . '</label>'; |
| | 265 | |
| | 266 | return $output; |
| | 267 | } |
| | 268 | |
| | 269 | function end_el($output, $category, $depth, $args) { |
| | 270 | if ( 'list' != $args['style'] ) |
| | 271 | return $output; |
| | 272 | |
| | 273 | $output .= "</li>\n"; |
| | 274 | return $output; |
| | 275 | } |
| | 276 | } |
| | 277 | |
| | 278 | function wp_category_checklist( $post_id ) { |
| | 279 | $walker = new Walker_Category_Checklist; |
| | 280 | |
| | 281 | $args = array(); |
| | 282 | $args['selected_cats'] = wp_get_post_categories($post_id); |
| | 283 | $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) ); |
| | 284 | $categories = get_categories('get=all'); |
| | 285 | $args = array($categories, 0, $args); |
| | 286 | $output = call_user_func_array(array(&$walker, 'walk'), $args); |
| | 287 | |
| | 288 | echo $output; |
| | 289 | } |