Category Cloud widget by Lee Kelleher. Author: Hugh Bassett-Jones Author URI: http://hugh.bassett-jones.com Version: 2 Based on Category Cloud widget by Lee Kelleher. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software */ class widget_catclouds extends WP_Widget { // declares the widget_catclouds class function widget_catclouds(){ $widget_ops = array('classname' => 'widget_catclouds', 'description' => __( "Displays selected categories as a tag cloud") ); $this->WP_Widget('catcloud', __('Category clouds'), $widget_ops); } // widget output function widget($args, $instance){ extract($args); echo $before_widget; // omit title if not specified if ($instance['title'] != '') echo $before_title . $instance['title'] . $after_title; // build query $query = 'show_option_all=1&style=cloud&show_count=1&use_desc_for_title=0&hierarchical=0'; $query .= '&order=' . $instance['order']; $query .= '&orderby=' . $instance['orderby']; if($instance['min_count'] > 0) { $query .= '&hide_empty=1';} // specified categories $inc_cats = array(); $exc_cats = array(); foreach (explode("," ,$instance['cats_inc_exc']) as $spec_cat) { if ($spec_cat < 0) { $exc_cats[] = abs($spec_cat); } elseif ( $spec_cat > 0) { $inc_cats[] = abs($spec_cat); } } if(count($inc_cats) > 0) { $query .= '&include=' . implode(",", $inc_cats); } if(count($exc_cats) > 0) { $query .= '&exclude=' . implode(",", $exc_cats); } // ensure minimum post count $cats = get_categories($query); foreach ($cats as $cat) { $catlink = get_category_link( $cat->cat_ID ); $catname = $cat->cat_name; $count = $cat->category_count; if ($count >= $instance['min_count']) { $counts{$catname} = $count; $catlinks{$catname} = $catlink; } } // font size calculation $spread = max($counts) - min($counts); if ($spread <= 0) { $spread = 1; }; $fontspread = $instance['max_size'] - $instance['min_size']; $fontstep = $spread / $fontspread; if ($fontspread <= 0) { $fontspread = 1; } echo '
'; foreach ($counts as $catname => $count) { $catlink = $catlinks{$catname}; echo "\n$catname "; } echo '
' . $after_widget; } // Creates the edit form for the widget. function form($instance){ //Defaults $instance = wp_parse_args( (array) $instance, array('min_size' => 50, 'max_size' => 150, 'unit' => '%', 'orderby' => 'name', 'order' => 'ASC', 'min' => 1, 'exclude'=>'') ); ?>