View Single Post
Old 10-18-2009, 10:57 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,235
wordpress tip: spice up your tag cloud

This will take your tag cloud and use random colors, instead of 1 color which is the default output.

add this to your themes functions.php file

Code:
function colorcloud($text) {
     $text = preg_replace_callback('|<a (.+?)>|i', 'colorcallback', $text);
     return $text;
}

function colorcallback($matches) {
     $text = $matches[1];
     $color = dechex(rand(0,16777215));
     $pattern = '/style=(\'|\")(.*)(\'|\")/i';
     $text = preg_replace($pattern, "style=\"color:#{$color};$2;\"", $text);
     return "<a $text>";
}

add_filter('wp_tag_cloud', 'colorcloud', 1);
and in your sidebar place the wp_tag_cloud() function.

Code:
<?php wp_tag_cloud('smallest=8&largest=24&number=50'); ?>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote