不用插件实现WordPress彩色标签云
WordPress自带的的标签云(Tag Cloud)默认的全部是一个颜色,只是大小不一样,所以在这里介绍一个不用插件就能显示彩色标签云的方法。
在主题的functions.php中增加以下函数
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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><a $text>"; } add_filter('wp_tag_cloud', 'colorCloud', 1); </a> |
此函数为玩WordPress的原创
然后正常调用wp_tag_cloud函数就可以了,下面附上wp_tag_cloud的参数说明:
(全文 …)