wordpress彩色标签云实现
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2014-04-29 06:04:39
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章
在functions.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);给标签云添加了过滤器后,就可以了,可以直接去看看小工具的效果,也可以不用小工具,而用代码调用标签云,在侧边栏位置加上下面的代码就行了
<?php //smllest为最小字体 largest为最大字体 number为标签数 wp_tag_cloud('smallest=8&largest=24&number=50'); ?>