Location: PHPKode > scripts > Tag Widget > custom-tag-widget/widget_28.php
<?php
// WP 2.8+ Sidebar widget

// Add our function to the widgets_init hook.
add_action('widgets_init', 'tags_load');

function tags_load() {
	register_widget('tags_Widget');
}

class tags_Widget extends WP_Widget {
	function tags_Widget() {
		/* Widget settings. */
		$widget_ops = array('classname' => 'tw', 'description' => __("Customizable cloud of your blog's tags."));

		/* Widget control settings. */
		$control_ops = array('width' => 250, 'height' => 510, 'id_base' => 'tw');

		/* Create the widget. */
		$this->WP_Widget('tw', __('Tags'), $widget_ops, $control_ops);
		$this->alt_option_name = 'widget_tw';
	}

	function widget($args, $instance) {
		$cache = wp_cache_get('widget_tw', 'widget');

		if (!is_array($cache))
			$cache = array();

		if (isset($cache[$args['widget_id']]))
			return $cache[$args['widget_id']];

		ob_start();
		extract($args);
		$title = apply_filters('widget_title', empty($instance['title']) ? __('Tags') : $instance['title']);

		$tagcloud = 'smallest='.$instance['smallest'];
		$tagcloud.= '&largest='.$instance['largest'];
		$tagcloud.= '&mincolor='.$instance['mincolor'];
		$tagcloud.= '&maxcolor='.$instance['maxcolor'];
		$tagcloud.= '&unit='.$instance['unit'];
		$tagcloud.= '&format='.$instance['format'];
		$tagcloud.= '&number='.$instance['number'];
		$tagcloud.= '&minnum='.$instance['minnum'];
		$tagcloud.= '&maxnum='.$instance['maxnum'];
		$tagcloud.= '&orderby='.$instance['orderby'];
		$tagcloud.= '&order='.$instance['order'];
		$tagcloud.= '&showcount='.$instance['showcount'];
		$tagcloud.= '&showcats='.$instance['showcats'];
		$tagcloud.= '&showtags='.$instance['showtags'];
		$tagcloud.= '&empty='.$instance['empty'];
		$tagcloud.= '&widget=yes';

		echo $before_widget;
		echo $before_title.$title.$after_title;
		echo '<div class="tw">';
			wdgt_tw($tagcloud);
		echo '</div>';
		echo $after_widget;

		$cache[$args['widget_id']] = ob_get_flush();
		wp_cache_add('widget_tw', $cache, 'widget');
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;

		$instance['title'] = strip_tags($new_instance['title']);
		$instance['number'] = (int) $new_instance['number'];
		$instance['minnum'] = (int) $new_instance['minnum'];
		$instance['maxnum'] = (int) $new_instance['maxnum'];
		$instance['unit'] = $new_instance['unit'];
		$instance['smallest'] = $new_instance['smallest'];
		$instance['largest'] = $new_instance['largest'];
		$instance['mincolor'] = strip_tags($new_instance['mincolor']);
		$instance['maxcolor'] = strip_tags($new_instance['maxcolor']);
		$instance['format'] = $new_instance['format'];
		$instance['orderby'] = $new_instance['orderby'];
		$instance['order'] = $new_instance['order'];
		$instance['showcount'] = $new_instance['showcount'];
		$instance['showcats'] = $new_instance['showcats'];
		$instance['showtags'] = $new_instance['showtags'];
		$instance['empty'] = $new_instance['empty'];
		$this->flush_widget_cache();

		$alloptions = wp_cache_get('alloptions', 'options');
		if (isset($alloptions['widget_tw']))
			delete_option('widget_tw');

		return $instance;
	}

	function flush_widget_cache() {
		wp_cache_delete('widget_tw', 'widget');
	}

	function form($instance) {
		/* Set up some default widget settings. */
		$defaults = array(
			'title' => 'Tags', 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => '',
			'minnum' => 0, 'maxnum' => 100, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
			'exclude' => '', 'include' => '', 'mincolor' => '', 'maxcolor' => '', 'showcount' => 'no',
			'showtags' => 'yes', 'showcats' => 'no', 'empty' => 'no', 'widget' => 'yes'
		);
		$instance = wp_parse_args((array) $instance, $defaults);
?>
	<style type="text/css">
	#widget-tags select { margin-bottom: 5px; width: 100px; }
	#widget-tags em { color: #666; font-size: .875em; }
	</style>
	<div id="widget-tags" class="widget-content">
			<p>
				<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" />
			</p>
			<p>
				<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of Tags to Display') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" value="<?php echo esc_attr($instance['number']); ?>" />
			</p>
			<p class="alignleft" style="padding-right: 20px; width: 100px;">
				<label for="<?php echo $this->get_field_id('minnum'); ?>"><?php _e('Min. Posts') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('minnum'); ?>" name="<?php echo $this->get_field_name('minnum'); ?>" value="<?php echo esc_attr($instance['minnum']); ?>" />
			</p>
			<p class="alignleft" style="width: 100px;">
				<label for="<?php echo $this->get_field_id('maxnum'); ?>"><?php _e('Max. Posts') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('maxnum'); ?>" name="<?php echo $this->get_field_name('maxnum'); ?>" value="<?php echo esc_attr($instance['maxnum']); ?>" />
			</p>
			
			<p class="clear alignleft" style="padding-right: 20px; width: 100px;">
				<label for="<?php echo $this->get_field_id('smallest'); ?>"><?php _e('Min. Font Size') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('smallest'); ?>" name="<?php echo $this->get_field_name('smallest'); ?>" value="<?php echo esc_attr($instance['smallest']); ?>" />
			</p>
			<p class="alignleft" style="width: 100px;">
				<label for="<?php echo $this->get_field_id('largest'); ?>"><?php _e('Max. Font Size') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('largest'); ?>" name="<?php echo $this->get_field_name('largest'); ?>" value="<?php echo esc_attr($instance['largest'], true); ?>" />
			</p>
			
			<p class="clear alignleft" style="padding-right: 20px; width: 100px;">
				<label for="<?php echo $this->get_field_id('mincolor'); ?>"><?php _e('Starting Color') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('mincolor'); ?>" name="<?php echo $this->get_field_name('mincolor'); ?>" value="<?php echo esc_attr($instance['mincolor'], true); ?>" />
				<em><?php _e('ex: #888888') ?></em>
			</p>
			<p class="alignleft" style="width: 100px;">
				<label for="<?php echo $this->get_field_id('maxcolor'); ?>"><?php _e('Ending Color') ?></label>
				<input type="text" class="widefat" id="<?php echo $this->get_field_id('maxcolor'); ?>" name="<?php echo $this->get_field_name('maxcolor'); ?>" value="<?php echo esc_attr($instance['maxcolor'], true); ?>" />
				<em><?php _e('ex: #bbbbbb') ?></em>
			</p>
			
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('format'); ?>"><?php _e('Cloud Format') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('format'); ?>" name="<?php echo $this->get_field_name('format'); ?>" size="1" value="">
						<option value="flat" <?php if ('flat' == $instance['format']) echo 'selected="selected"'; ?>>Flat</option>
						<option value="list" <?php if ('list' == $instance['format']) echo 'selected="selected"'; ?>>List</option>
						<option value="drop" <?php if ('drop' == $instance['format']) echo 'selected="selected"'; ?>>Dropdown</option>
		   			</select>				
			</p>
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('unit'); ?>"><?php _e('Font Display Unit') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('unit'); ?>" name="<?php echo $this->get_field_name('unit'); ?>">
						<option value="px" <?php if ('px' == $instance['unit']) echo 'selected="selected"'; ?>>Pixel</option>
						<option value="pt" <?php if ('pt' == $instance['unit']) echo 'selected="selected"'; ?>>Point</option>
						<option value="em" <?php if ('em' == $instance['unit']) echo 'selected="selected"'; ?>>Em</option>
						<option value="%" <?php if ('%' == $instance['unit']) echo 'selected="selected"'; ?>>Percent</option>
					</select>
			</p>
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('showtags'); ?>"><?php _e('Show Tags') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('showtags'); ?>" name="<?php echo $this->get_field_name('showtags'); ?>" size="1" value="">
						<option value="yes" <?php if ('yes' == $instance['showtags']) echo 'selected="selected"'; ?>>Yes</option>
						<option value="no" <?php if ('no' == $instance['showtags']) echo 'selected="selected"'; ?>>No</option>
		   			</select>				
			</p>
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('showcats'); ?>"><?php _e('Show Categories') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('showcats'); ?>" name="<?php echo $this->get_field_name('showcats'); ?>" size="1" value="">
						<option value="no" <?php if ('no' == $instance['showcats']) echo 'selected="selected"'; ?>>No</option>
						<option value="yes" <?php if ('yes' == $instance['showcats']) echo 'selected="selected"'; ?>>Yes</option>
		   			</select>				
			</p>
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('empty'); ?>"><?php _e('Show Empty') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('empty'); ?>" name="<?php echo $this->get_field_name('empty'); ?>" size="1" value="">
						<option value="no" <?php if ('no' == $instance['empty']) echo 'selected="selected"'; ?>>No</option>
						<option value="yes" <?php if ('yes' == $instance['empty']) echo 'selected="selected"'; ?>>Yes</option>
		   			</select>
			</p>
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('showcount'); ?>"><?php _e('Display Post Count') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('showcount'); ?>" name="<?php echo $this->get_field_name('showcount'); ?>" size="1" value="">
						<option value="no" <?php if ('no' == $instance['showcount']) echo 'selected="selected"'; ?>>No</option>
						<option value="yes" <?php if ('yes' == $instance['showcount']) echo 'selected="selected"'; ?>>Yes</option>
		   			</select>
			</p>
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e('Sort By') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('orderby'); ?>" name="<?php echo $this->get_field_name('orderby'); ?>" size="1" value="">
						<option value="name" <?php if ('name' == $instance['orderby']) echo 'selected="selected"'; ?>>Name</option>
						<option value="count" <?php if ('count' == $instance['orderby']) echo 'selected="selected"'; ?>>Count</option>
						<option value="rand" <?php if ('rand' == $instance['orderby']) echo 'selected="selected"'; ?>>Random</option>
		   			</select>				
			</p>
			<p class="clear">
				<label class="alignleft" style="padding: 5px" for="<?php echo $this->get_field_id('order'); ?>"><?php _e('Sort Order') ?></label>
					<select class="alignright" id="<?php echo $this->get_field_id('order'); ?>" name="<?php echo $this->get_field_name('order'); ?>" size="1" value="">
						<option value="ASC" <?php if ('ASC' == $instance['order']) echo 'selected="selected"'; ?>>Ascending</option>
						<option value="DESC" <?php if ('DESC' == $instance['order']) echo 'selected="selected"'; ?>>Descending</option>
		   			</select>
			</p>
	</div>
<?php
	}
}
?>
Return current item: Tag Widget