不用标签实现wordpress彩色标签云
效果如图:
代码如下:
<?php
function colorCloud($text) {
$text = preg_replace_callback(‘|<a (.+?)>|i’, ‘colorCloudCallback’, $text);
return $text;
}
function colorCloudCallback($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);
?>
function colorCloud($text) {
$text = preg_replace_callback(‘|<a (.+?)>|i’, ‘colorCloudCallback’, $text);
return $text;
}
function colorCloudCallback($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);
?>
将代码写到functions.php中,(注意<?php ?>开关)然后在小工具里,添加一个默认的标签云工具就可以了。注意:可能会和wp colums FLASH标签云冲突
文章转自互联网。。。非本站原创。
效果见本站adsimple主题边栏。
No related posts.
<« 传说中的高科技


[...] 另:此PHP代码为不用插件实现wordpress标签云 [...]