打开网站目录下模板所在文件夹functions.php
增加如下代码:
//Color Tag Cloud 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);
这时,可以在后台看看小工具的效果,如果用小工具的话,不能控制显示的标签数量,当标签很多的时候,就会把页面撑的很大
如果要控制显示数量的话,这里添加如下代码到侧边栏
<?php //smllest为最小字体 largest为最大字体 number为标签数 wp_tag_cloud('smallest=8&largest=24&number=50'); ?>