标签云 对我们的文章画龙点睛,如果让我们的标签云随机产生彩色效果,更是增加了个性化
B2标签云将以下代码均添加于子主题根目录下的functions.php中
[content_hide]
//彩色静态标签云 www.micnt.com
function colorCloud($text) {
$text = preg_replace_callback('|<a (.+?)>|i', 'colorCloudCallback', $text);
$text=preg_replace('/<a /','<a ',$text);
return $text;
}
function colorCloudCallback($matches) {
$text = $matches[1];
$a = array('8D7EEA','F99FB2','AEE05B','E8D368','F75D78','55DCAB','F75DB1','ABABAF','7EA8EA','F99','C9C','F96','6CC','6C9','37A7FF','B0D686','E6CC6E');
$co = array_rand($a,2);
$color = $a[$co[0]];
$pattern = '/style=(\'|\")(.*)(\'|\")/i';
$text = preg_replace($pattern, "style=\"display: inline-block; display: inline; zoom: 1; color: #fff; padding: 1px 5px; margin: 0 5px 5px 0; background-color: #{$color}; border-radius: 3px; -webkit-transition: background-color .4s linear; -moz-transition: background-color .4s linear; transition: background-color .4s linear;\"", $text);
return "<a $text>";
}
add_filter('wp_tag_cloud', 'colorCloud', 1);
[/content_hide]
评论前必须登录!
注册