就上兩天,我把主題自帶的彩色標(biāo)簽云顯示方法去掉了,因?yàn)槲铱淳昧�,感覺讓眼睛花花的,但也有不少的朋友挺喜歡那種效果的,所以我就把如何實(shí)現(xiàn)彩色標(biāo)簽云顯示的方法寫出來。
其實(shí)實(shí)現(xiàn)標(biāo)簽云彩色顯示的方法很簡單,就是通過向 functions.php 文件添加一段代碼來實(shí)現(xiàn)的。
添加的代碼如下:
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);
注意:如果你使用的主題沒有 functions.php 文件,那么你需要在你使用的主題目錄中新建一個 functions.php 文件,不過別忘記在開始處添加 <?php 與在結(jié)尾處添加?> 。
原文地址:
感謝 晨光博客 的投稿
Copyright since 2005,問鼎科技(58wd.com) 服務(wù)電話:400-666-4165 地址:成都市IT大道蜀清路239號 蜀ICP備10202221號