WordPress.org

Make WordPress Core

Changeset 10896


Ignore:
Timestamp:
04/08/09 19:37:33 (6 years ago)
Author:
ryan
Message:

Allowing displaying links from a specific category in the links widget. Props Denis-de-Bernardy. fixes #9449

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-widgets.php

    r10853 r10896  
    103103        $show_rating = isset($instance['rating']) ? $instance['rating'] : false; 
    104104        $show_images = isset($instance['images']) ? $instance['images'] : true; 
     105        $category = isset($instance['category']) ? $instance['category'] : false; 
     106 
     107        if ( is_admin() && !$category ) { 
     108            // Display All Links widget as such in the widgets screen 
     109            echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget; 
     110            return; 
     111        } 
    105112 
    106113        $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget); 
     
    110117            'show_images' => $show_images, 'show_description' => $show_description, 
    111118            'show_name' => $show_name, 'show_rating' => $show_rating, 
    112             'class' => 'linkcat widget' 
     119            'category' => $category, 'class' => 'linkcat widget' 
    113120        ))); 
    114121    } 
     
    121128                $instance[$field] = 1; 
    122129        } 
     130        $instance['category'] = intval($new_instance['category']); 
    123131 
    124132        return $instance; 
     
    128136 
    129137        //Defaults 
    130         $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false) ); 
     138        $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) ); 
     139        $link_cats = get_terms( 'link_category'); 
    131140?> 
    132141        <p> 
     142        <label for="<?php echo $this->get_field_id('category'); ?>"> 
     143        <select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" style="width: 97%;" /> 
     144        <option value=""><?php _e('All Links'); ?></option> 
     145        <?php 
     146        foreach ( $link_cats as $link_cat ) { 
     147            echo '<option value="' . intval($link_cat->term_id) . '"' 
     148                . ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' ) 
     149                . '>' . $link_cat->name . "</option>\n"; 
     150        } 
     151        ?> 
     152        </select></label><br /> 
    133153        <label for="<?php echo $this->get_field_id('images'); ?>"> 
    134154        <input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" /> <?php _e('Show Link Image'); ?></label><br /> 
Note: See TracChangeset for help on using the changeset viewer.