.+?) (.+)#', '$1 $2', $tag);
return $tag;
}
// Install hook
register_activation_hook(__FILE__,'nktagcloud_install');
function nktagcloud_install() {
update_option('nktagcloud_title', 'Tags');
update_option('nktagcloud_smallest', '8');
update_option('nktagcloud_largest', '22');
update_option('nktagcloud_unit', 'pt');
update_option('nktagcloud_number', '0');
update_option('nktagcloud_format', 'list');
update_option('nktagcloud_order', 'ASC');
update_option('nktagcloud_orderby', 'name');
update_option('nktagcloud_homelink', 'No');
update_option('nktagcloud_rmcss', 'No');
update_option('nktagcloud_replace', 'No');
update_option('nktagcloud_inject_count', 'No');
}
function nktagcloud_control() { ?>
Sorry, there were too many options, so I had to move the configuration
to a settings page.
Better Tag Cloud
The default tag cloud widget that comes with wordpress is very simple. This widget makes the options for wp_tag_cloud() and more available to the a new tag cloud widget.
My other plugins
Theme switch:
I like to tweak my main theme that I use on a varity of blogs. If you have ever done this you know how annoying it can be to break things for visitors of your blog. This plugin allows you to use a different theme than the one used for your visitors when you are logged in.
Rhyming widget:
I wrote a little online rhyming dictionary. This is a widget to search it directly from one of your sidebars.
Snow and more:
This one lets you see snowflakes (or other, custom images) fall down your blog.
Fireworks:
The name says it all, see fireworks on your blog!
Contact
Feel free to send me feedback, patches, feature requests etc. to my mail address or to blog about this plugin. Visit my blog at nkuttler.de or this plugin's page at nktagcloud to discuss it.
Please remember to rate this widget, especially if you like it.
Widget Configuration
Please see the wp_tag_cloud() page for a detailed description of the options.
Tag cloud widget powered by nktagcloud
8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
'exclude' => '', 'include' => '', 'link' => 'view'
);
$args = wp_parse_args( $args, $defaults );
$tags = get_tags( array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
if ( empty( $tags ) )
return;
foreach ( $tags as $key => $tag ) {
if ( 'edit' == $args['link'] )
$link = get_edit_tag_link( $tag->term_id );
else
$link = get_tag_link( $tag->term_id );
if ( is_wp_error( $link ) )
return false;
$tags[ $key ]->link = $link;
$tags[ $key ]->id = $tag->term_id;
}
$return = nk_wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
$return = apply_filters( 'wp_tag_cloud', $return, $args );
if ( 'array' == $args['format'] )
return $return;
echo $return;
}
/**
* Generates a tag cloud (heatmap) from provided data.
*
* The text size is set by the 'smallest' and 'largest' arguments, which will
* use the 'unit' argument value for the CSS text size unit. The 'format'
* argument can be 'flat' (default), 'list', or 'array'. The flat value for the
* 'format' argument will separate tags with spaces. The list value for the
* 'format' argument will format the tags in a UL HTML list. The array value for
* the 'format' argument will return in PHP array type format.
*
* The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
* The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or
* 'RAND'.
*
* The 'number' argument is how many tags to return. By default, the limit will
* be to return the entire tag cloud list.
*
* The 'topic_count_text_callback' argument is a function, which given the count
* of the posts with that tag returns a text for the tooltip of the tag link.
*
* @todo Complete functionality.
* @since 2.3.0
*
* @param array $tags List of tags.
* @param string|array $args Optional, override default arguments.
* @return string
*/
function nk_wp_generate_tag_cloud( $tags, $args = '' ) {
global $wp_rewrite;
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
'topic_count_text_callback' => 'default_topic_count_text',
);
if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
$body = 'return sprintf (
__ngettext('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count),
number_format_i18n( $count ));';
$args['topic_count_text_callback'] = create_function('$count', $body);
}
$args = wp_parse_args( $args, $defaults );
extract( $args );
if ( empty( $tags ) )
return;
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
if ( 'name' == $orderby )
uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
else
uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
if ( 'DESC' == $order )
$tags = array_reverse( $tags, true );
elseif ( 'RAND' == $order ) {
$keys = array_rand( $tags, count( $tags ) );
foreach ( $keys as $key )
$temp[$key] = $tags[$key];
$tags = $temp;
unset( $temp );
}
/* nkuttler: support sorting by two criteria */
if (get_option('nktagcloud_order') == 'both') {
$orderby = 'both';
}
if ('both' == $orderby) {
function compare_both($a, $b) {
$retval = strnatcmp($b->count, $a->count);
if(!$retval) return strnatcmp($a->name, $b->name);
return $retval;
}
usort($tags, 'compare_both');
}
/* end changes */
if ( $number > 0 )
$tags = array_slice($tags, 0, $number);
$counts = array();
foreach ( (array) $tags as $key => $tag )
$counts[ $key ] = $tag->count;
$min_count = min( $counts );
$spread = max( $counts ) - $min_count;
if ( $spread <= 0 )
$spread = 1;
$font_spread = $largest - $smallest;
if ( $font_spread < 0 )
$font_spread = 1;
$font_step = $font_spread / $spread;
$a = array();
$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
/* added and modified nkuttler */
function nk_add_counter($tag = NULL) {
if (get_option('nktagcloud_inject_count') == 'Yes') {
$inject = ' (' . $tag->count . ')';
return $inject;
}
}
foreach ( $tags as $key => $tag ) {
$count = $counts[ $key ];
$tag_link = '#' != $tag->link ? clean_url( $tag->link ) : '#';
$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
$tag_name = $tags[ $key ]->name;
$a[] = "$tag_name". nk_add_counter($tag) ."";
}
/* end changes */
switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "\n\t- ";
$return .= join( "
\n\t- ", $a );
$return .= "
\n
\n";
break;
default :
$return = join( "\n", $a );
break;
endswitch;
return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
}
?>