WordPress.org

Make WordPress Core

Changeset 13276


Ignore:
Timestamp:
02/21/2010 02:47:58 AM (8 years ago)
Author:
dd32
Message:

Allow the Tag Cloud Widget to support non-tag taxonomies. Props Sivel. Fixes #11612

File:
1 edited

Legend:

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

    r13268 r13276  
    977977    function widget( $args, $instance ) {
    978978        extract($args);
    979         $title = apply_filters('widget_title', empty($instance['title']) ? __('Tags') : $instance['title'], $instance, $this->id_base);
     979        $current_taxonomy = $this->_get_current_taxonomy($instance);
     980        if ( !empty($instance['title']) ) {
     981            $title = $instance['title'];
     982        } else {
     983            if ( 'post_tag' == $current_taxonomy ) {
     984                $title = __('Tags');
     985            } else {
     986                $tax = get_taxonomy($current_taxonomy);
     987                $title = $tax->label;
     988            }
     989        }
     990        $title = apply_filters('widget_title', $title, $instance, $this->id_base);
    980991
    981992        echo $before_widget;
     
    983994            echo $before_title . $title . $after_title;
    984995        echo '<div>';
    985         wp_tag_cloud(apply_filters('widget_tag_cloud_args', array()));
     996        wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
    986997        echo "</div>\n";
    987998        echo $after_widget;
     
    9901001    function update( $new_instance, $old_instance ) {
    9911002        $instance['title'] = strip_tags(stripslashes($new_instance['title']));
     1003        $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
    9921004        return $instance;
    9931005    }
    9941006
    9951007    function form( $instance ) {
     1008        $current_taxonomy = $this->_get_current_taxonomy($instance);
    9961009?>
    9971010    <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
    9981011    <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
    999 <?php
     1012    <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
     1013    <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
     1014    <?php foreach ( get_object_taxonomies('post') as $taxonomy ) :
     1015                $tax = get_taxonomy($taxonomy);
     1016                if ( !$tax->show_tagcloud || empty($tax->label) )
     1017                    continue;
     1018    ?>
     1019        <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->label ?></option>
     1020    <?php endforeach; ?>
     1021    </select></p><?php
     1022    }
     1023
     1024    function _get_current_taxonomy($instance) {
     1025        if ( !empty($instance['taxonomy']) && is_taxonomy($instance['taxonomy']) )
     1026            return $instance['taxonomy'];
     1027
     1028        return 'post_tag';
    10001029    }
    10011030}
Note: See TracChangeset for help on using the changeset viewer.