diff options
author | ryan <ryan@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-05-19 22:17:49 +0000 |
---|---|---|
committer | ryan <ryan@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-05-19 22:17:49 +0000 |
commit | bb785c8b708131cf80d8e9b8215f41a5196bd09b (patch) | |
tree | e1d65e7ec4f97a2f11ff8abb5b69bab565207821 /wp-admin/includes | |
parent | 80788a01b4ded035ff65ce65def9ad6f57822c89 (diff) | |
download | wordpress-mu-bb785c8b708131cf80d8e9b8215f41a5196bd09b.tar.gz wordpress-mu-bb785c8b708131cf80d8e9b8215f41a5196bd09b.tar.xz wordpress-mu-bb785c8b708131cf80d8e9b8215f41a5196bd09b.zip |
Put checked categories at the top of the checklist. Props mdawaffe. see #WP7000
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1299 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/includes')
-rw-r--r-- | wp-admin/includes/template.php | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index db80bf8..19f11f6 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -148,19 +148,24 @@ class Walker_Category_Checklist extends Walker { } } -function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false ) { +function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false ) { $walker = new Walker_Category_Checklist; $descendants_and_self = (int) $descendants_and_self; $args = array(); - if ( $post_id ) + if ( is_array( $selected_cats ) ) + $args['selected_cats'] = $selected_cats; + elseif ( $post_id ) $args['selected_cats'] = wp_get_post_categories($post_id); else $args['selected_cats'] = array(); - if ( is_array( $selected_cats ) ) - $args['selected_cats'] = $selected_cats; - $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); + + if ( is_array( $popular_cats ) ) + $args['popular_cats'] = $popular_cats; + else + $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); + if ( $descendants_and_self ) { $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" ); $self = get_category( $descendants_and_self ); @@ -169,13 +174,22 @@ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $select $categories = get_categories('get=all'); } - $args = array($categories, 0, $args); - $output = call_user_func_array(array(&$walker, 'walk'), $args); + // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) + $checked_categories = array(); + for ( $i = 0; isset($categories[$i]); $i++ ) { + if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) { + $checked_categories[] = $categories[$i]; + unset($categories[$i]); + } + } - echo $output; + // Put checked cats on top + echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); + // Then the rest of them + echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); } -function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) { +function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { global $post_ID; if ( $post_ID ) $checked_categories = wp_get_post_categories($post_ID); @@ -186,6 +200,8 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) { $popular_ids = array(); foreach ( (array) $categories as $category ) { $popular_ids[] = $category->term_id; + if ( !$echo ) // hack for AJAX use + continue; $id = "popular-category-$category->term_id"; ?> |