首页 » 精选软件 » wordpress 不用插件显示彩色标签云

wordpress 不用插件显示彩色标签云

默认的标签显示是黑色字体,而且查找起来很麻烦,不做加点颜色显示更加生动直观,当然有的插件可以实现还有的是3D标签云,但那就跟我站简约大方的主题不符,现在把我站标签实现的方法分享给大家

修改主题文件夹里的funcations.php,在最后一行追加

<?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);
?>

保存,替换原文件即可。

打赏

目前这篇文章有1条评论(Rss)评论关闭。

  1. Efrain Koogler | #1
    2011-12-21 at 07:12

    Good morning! I was surfing arround on Bing and came across your website. Nice articles and info! I also have a blog . Please feel free to leave a comment there.