看到許多博客都有標簽聚合的功效,因而花瞭點兒時光找瞭找,在倡萌博客找到瞭這個辦法
上面和人人同享下
起首復制一份你博客主題的page.php模板
然後在其頂部參加
<?php
/*
Template Name: Tags
*/
?>
然後將這類表現註釋內容的代碼換成挪用tags的代碼
<?php the_content(); ?>
換成
<?php wp_tag_cloud(smallest=12largest=18unit=pxnumber=0orderby=countorder=DESC);?>
在style.css內裡增長以下代碼可使得間距更悅目:
#page-cnt.tags,
#page-cnt.friends { height: 576px; padding: 6px 0 0; overflow: hidden; line-height: 30px; }
#page-cnt.tags,
#page-cnt.friends { height: auto; padding-top: 5px; overflow: visible; }
.tags a { display: inline-block; margin: 0 4px; white-space: nowrap; }
翻開主題中的functions.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);
大功樂成,在背景新建一個tags頁面便可以瞭
本文地點:/website/20120802.html