Make WordPress Core


Ignore:
Timestamp:
04/14/2008 07:31:46 PM (18 years ago)
Author:
ryan
Message:

More efficient category and list JS from mdawaffe. fixes #6677 for 2.5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/wp-admin/includes/template.php

    r7596 r7670  
    176176}
    177177
    178 function write_nested_categories( $categories ) {
     178function write_nested_categories( $categories, $popular_ids = array() ) {
    179179    foreach ( $categories as $category ) {
    180         echo "\n", '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), '</label>';
     180        $class = in_array( $category['cat_ID'], $popular_ids ) ? ' class="popular-category"' : '';
     181        echo "\n", "<li id='category-$category[cat_ID]'$class>", '<label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), '</label>';
    181182
    182183        if ( $category['children'] ) {
     
    189190}
    190191
    191 function dropdown_categories( $default = 0, $parent = 0 ) {
    192     write_nested_categories( get_nested_categories( $default, $parent ) );
     192function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) {
     193    write_nested_categories( get_nested_categories( $default, $parent ), $popular_ids );
    193194}
    194195
     
    196197    $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) );
    197198
     199    $popular_ids = array();
    198200    foreach ( (array) $categories as $category ) {
     201        $popular_ids[] = $category->term_id;
    199202        $id = "popular-category-$category->term_id";
    200203        ?>
    201204
    202         <li id="<?php echo $id; ?>" >
     205        <li id="<?php echo $id; ?>" class="popular-category">
    203206            <label class="selectit" for="in-<?php echo $id; ?>">
    204207            <input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" />
     
    209212        <?php
    210213    }
     214    return $popular_ids;
    211215}
    212216
Note: See TracChangeset for help on using the changeset viewer.