Loading... <p>wordpress彩色标签云,用上它后感觉标签云不再单调,看着也舒服啊!需要的朋友一定要试试啊,就一段代码,太直接了,拥有自己的彩色标签云!网上方法实在太多,不知道是谁原创了,我就不标明了,下面的方法产生的标签云色彩是随机的。就是我现在的博客的标签云的样子!</p> <p>将以下代码放入当前主题(theme)的 functions.php 文件中,要放在<?php…?>中间。</p> <p> <br />function colorCloud($text) { <br />$text = preg_replace_callback('|<a (.+?)>|i', 'colorCloudCallback', $text); <br />return $text; <br />} <br />function colorCloudCallback($matches) { <br />$text = $matches[1]; <br />$color = dechex(rand(0,16777215)); <br />$pattern = '/style=(\'|\")(.*)(\'|\")/i'; <br />$text = preg_replace($pattern, "style=\"color:#{$color};$2;\"", $text); <br />return "<a $text>"; <br />} <br />add_filter('wp_tag_cloud', 'colorCloud', 1);</p> <p> </p> <p>说明下:$color = dechex(rand(0,16777215)); 作用是定义标签随机颜色的十进制数值范围,0 等于#000,16777215 等于#fff。你可以使用进制换算工具换算后修改这行代码,改变颜色范围。</p> Last modification:October 6, 2023 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的文章对你有用,请随意赞赏