實現Wordpress彩色標籤雲
在相應主題的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);
修改Wordpress彩色標籤字型大小,排序,顯示數量等。
檔案位置在wp-includes下的category-template.php 檔案中,搜尋wp_tag_cloud,找到相關引數進行修改:
function wp_tag_cloud( $args = "" ) {
$defaults = array(
"smallest" => 12, "largest" => 16, "unit" => "pt", "number" => 50,
"format" => "flat", "separator" => "\n", "orderby" => "count", "order" => "DESC",
"exclude" => "", "include" => "", "link" => "view", "taxonomy" => "post_tag", "echo" => true
);
$args = wp_parse_args( $args, $defaults );
$tags = get_terms( $args["taxonomy"], array_merge( $args, array( "orderby" => "count", "order" => "DESC" ) ) );
注:
smallest表示標籤的最小字號
largest表示最大字號
unit=px表示字型使用畫素單位
number=0表示顯示所有標籤,如果為40,表示顯示40個
orderby=count表示按照標籤所關聯的文章數來排列
order=DESC表示降序排序(ASC表示升序排序,DESC表示降序排序)
Wordpress彩色標籤雲小工具呼叫。
儲存之後回到首頁就可以看到彩色標籤雲的效果了。
實現Wordpress彩色標籤雲
在相應主題的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);
修改Wordpress彩色標籤字型大小,排序,顯示數量等。
檔案位置在wp-includes下的category-template.php 檔案中,搜尋wp_tag_cloud,找到相關引數進行修改:
function wp_tag_cloud( $args = "" ) {
$defaults = array(
"smallest" => 12, "largest" => 16, "unit" => "pt", "number" => 50,
"format" => "flat", "separator" => "\n", "orderby" => "count", "order" => "DESC",
"exclude" => "", "include" => "", "link" => "view", "taxonomy" => "post_tag", "echo" => true
);
$args = wp_parse_args( $args, $defaults );
$tags = get_terms( $args["taxonomy"], array_merge( $args, array( "orderby" => "count", "order" => "DESC" ) ) );
注:
smallest表示標籤的最小字號
largest表示最大字號
unit=px表示字型使用畫素單位
number=0表示顯示所有標籤,如果為40,表示顯示40個
orderby=count表示按照標籤所關聯的文章數來排列
order=DESC表示降序排序(ASC表示升序排序,DESC表示降序排序)
Wordpress彩色標籤雲小工具呼叫。
儲存之後回到首頁就可以看到彩色標籤雲的效果了。