| 1 | function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $include_self = 0, $selected_cats = false ) {
|
|---|
| 2 | $walker = new Walker_Category_Checklist;
|
|---|
| 3 | $descendants_and_self = (int) $descendants_and_self;
|
|---|
| 4 |
|
|---|
| 5 | args = array();
|
|---|
| 6 |
|
|---|
| 7 | if ( $post_id )
|
|---|
| 8 | $args['selected_cats'] = wp_get_post_categories($post_id);
|
|---|
| 9 | else
|
|---|
| 10 | $args['selected_cats'] = array();
|
|---|
| 11 | if ( is_array( $selected_cats ) )
|
|---|
| 12 | $args['selected_cats'] = $selected_cats;
|
|---|
| 13 | $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
|
|---|
| 14 | if ( $descendants_and_self ) {
|
|---|
| 15 | $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
|
|---|
| 16 | if ( $include_self ) {
|
|---|
| 17 | $self = get_category( $descendants_and_self );
|
|---|
| 18 | array_unshift( $categories, $self );
|
|---|
| 19 | }
|
|---|
| 20 | } else {
|
|---|
| 21 | $categories = get_categories('get=all');
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | $args = array($categories, 0, $args);
|
|---|
| 25 | $output = call_user_func_array(array(&$walker, 'walk'), $args);
|
|---|
| 26 |
|
|---|
| 27 | echo $output;
|
|---|
| 28 | }
|
|---|