| 1 | Index: wp-admin/includes/meta-boxes.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-admin/includes/meta-boxes.php (revision 17488) |
|---|
| 4 | +++ wp-admin/includes/meta-boxes.php (working copy) |
|---|
| 5 | @@ -652,7 +652,9 @@ |
|---|
| 6 | * |
|---|
| 7 | * @param object $link |
|---|
| 8 | */ |
|---|
| 9 | -function link_categories_meta_box($link) { ?> |
|---|
| 10 | +function link_categories_meta_box($link) { |
|---|
| 11 | + $link_id = isset( $link->link_id ) ? $link->link_id : 0; |
|---|
| 12 | + ?> |
|---|
| 13 | <ul id="category-tabs" class="category-tabs"> |
|---|
| 14 | <li class="tabs"><a href="#categories-all"><?php _e( 'All Categories' ); ?></a></li> |
|---|
| 15 | <li class="hide-if-no-js"><a href="#categories-pop"><?php _e( 'Most Used' ); ?></a></li> |
|---|
| 16 | @@ -660,18 +662,13 @@ |
|---|
| 17 | |
|---|
| 18 | <div id="categories-all" class="tabs-panel"> |
|---|
| 19 | <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> |
|---|
| 20 | - <?php |
|---|
| 21 | - if ( isset($link->link_id) ) |
|---|
| 22 | - wp_link_category_checklist($link->link_id); |
|---|
| 23 | - else |
|---|
| 24 | - wp_link_category_checklist(); |
|---|
| 25 | - ?> |
|---|
| 26 | + <?php wp_link_category_checklist( $link_id ); ?> |
|---|
| 27 | </ul> |
|---|
| 28 | </div> |
|---|
| 29 | |
|---|
| 30 | <div id="categories-pop" class="tabs-panel" style="display: none;"> |
|---|
| 31 | <ul id="categorychecklist-pop" class="categorychecklist form-no-clear"> |
|---|
| 32 | - <?php wp_popular_terms_checklist('link_category'); ?> |
|---|
| 33 | + <?php wp_link_category_checklist( $link_id, true); ?> |
|---|
| 34 | </ul> |
|---|
| 35 | </div> |
|---|
| 36 | |
|---|
| 37 | Index: wp-admin/includes/template.php |
|---|
| 38 | =================================================================== |
|---|
| 39 | --- wp-admin/includes/template.php (revision 17488) |
|---|
| 40 | +++ wp-admin/includes/template.php (working copy) |
|---|
| 41 | @@ -190,13 +190,16 @@ |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | - * {@internal Missing Short Description}} |
|---|
| 46 | + * Display a checklist of link categories |
|---|
| 47 | * |
|---|
| 48 | * @since 2.5.1 |
|---|
| 49 | * |
|---|
| 50 | - * @param unknown_type $link_id |
|---|
| 51 | + * @param int $link_id optional The ID of the link for which to display categories |
|---|
| 52 | + * @param bool $popular optional Whether to show the most popular categories If set to false, |
|---|
| 53 | + * then all categories will be shown |
|---|
| 54 | + * @param int $number optional The number of popular categories to show. |
|---|
| 55 | */ |
|---|
| 56 | -function wp_link_category_checklist( $link_id = 0 ) { |
|---|
| 57 | +function wp_link_category_checklist( $link_id = 0, $popular = false, $number = 10 ) { |
|---|
| 58 | $default = 1; |
|---|
| 59 | |
|---|
| 60 | if ( $link_id ) { |
|---|
| 61 | @@ -208,7 +211,11 @@ |
|---|
| 62 | $checked_categories[] = $default; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | - $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); |
|---|
| 66 | + if ( $popular ) |
|---|
| 67 | + $categories = get_terms( 'link_category', array( 'orderby' => 'count', 'order' => 'desc', 'limit' => (int)$popular, 'hide_empty' => 0 ) ); |
|---|
| 68 | + else |
|---|
| 69 | + $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); |
|---|
| 70 | + |
|---|
| 71 | |
|---|
| 72 | if ( empty( $categories ) ) |
|---|
| 73 | return; |
|---|
| 74 | @@ -217,7 +224,11 @@ |
|---|
| 75 | $cat_id = $category->term_id; |
|---|
| 76 | $name = esc_html( apply_filters( 'the_category', $category->name ) ); |
|---|
| 77 | $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; |
|---|
| 78 | - echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>"; |
|---|
| 79 | + |
|---|
| 80 | + if( $popular ) |
|---|
| 81 | + echo "<li class='popular-category' id='popular-link-category-$cat_id'><label for='in-popular-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' id='in-popular-category-$cat_id' $checked /> $name </label></li>"; |
|---|
| 82 | + else |
|---|
| 83 | + echo "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' name='link_category[]' id='in-link-category-$cat_id' $checked /> $name </label></li>"; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|