'widget_acc_tag_cloud', 'description' => __('Display an accessible tag cloud in the sidebar', 'acc-tag-cloud') ); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'acc-tag-cloud-widget' ); /* Create the widget. */ $this->WP_Widget( 'acc-tag-cloud-widget', __('Accessible Tag Cloud Widget', 'acc-tag-cloud'), $widget_ops, $control_ops ); } /** * How to display the widget on the screen. */ function widget( $args, $instance ) { extract( $args ); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title'] ); $smallest = $instance['smallest']; $biggest = $instance['biggest']; $unit = $instance['unit']; $taxonomy = $instance['taxonomy']; $count = $instance['count']; if(!$count){ $count=10; } if ( !empty($instance['title']) ) { $title = $instance['title']; } else { if ( 'post_tag' == $current_taxonomy ) { $title = __('Tags'); } else { $tax = get_taxonomy($current_taxonomy); $title = $tax->label; } } $title = apply_filters('widget_title', $title, $instance, $this->id_base); $terms = get_terms($taxonomy, array('number' => $count)); $sizerange=$biggest-$smallest; $lowestcount=$terms[0]->count; $highestcount=0; foreach ($terms as $term) { if ($term->count < $lowestcount) { $lowestcount = $term->count; } else if($term->count > $highestcount) { $highestcount = $term->count; } } $countdiff=$highestcount-$lowestcount; if ($countdiff==0){ foreach ($terms as $term) { $term->size=$smallest+($sizerange/2); } } else { foreach ($terms as $term) { $term->size=$smallest+(($term->count-$lowestcount)/$countdiff)*$sizerange; } } $tagcloud=""; foreach ($terms as $term){ $tagcloud.="
  • slug."'>The tag ‘".$term->name."’ contains ".$term->count." posts
  • "; } /* Before widget (defined by themes). */ echo $before_widget; if ( $title ) { echo $before_title . $title . $after_title; } echo("
      "); echo($tagcloud); echo("
    "); /*echo('
    ');
    		print_r($terms);
    		print_r($instance);
    		echo('
    '); echo('
    ');
    		print_r($sizerange);
    		echo('
    '); echo('
    ');
    		print_r($lowestcount);
    		echo('
    '); echo('
    ');	
    		print_r($highestcount);
    		echo('
    '); echo('
    ');
    		print_r($countdiff);
    		echo('
    ');*/ /* After widget (defined by themes). */ echo $after_widget; } /** * Update the widget settings. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['smallest'] = strip_tags( $new_instance['smallest'] ); $instance['biggest'] = strip_tags($new_instance['biggest']); $instance['taxonomy'] = strip_tags($new_instance['taxonomy']); $instance['unit'] = strip_tags($new_instance['unit']); $instance['count'] = strip_tags($new_instance['count']); return $instance; } /** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function _get_current_taxonomy($instance) { if ( !empty($instance['taxonomy']) && is_taxonomy($instance['taxonomy']) ) return $instance['taxonomy']; return 'post_tag'; } function form( $instance ) { ?>