有些WordPress主題使用的是WordPress自帶的標籤雲小工具,默認的顯示個數、字體大小、排序等也許不能滿足你的需求,好在WordPress提供了 widget_tag_cloud_args 這個 filter可以修改默認的參數。
在你當前主題的 functions.php 文件添加下面的代碼即可:
//custom widget tag cloud
add_filter( 'widget_tag_cloud_args', 'theme_tag_cloud_args' );
function theme_tag_cloud_args( $args ){
$newargs = array(
'smallest' => 8, //最小字號
'largest' => 22, //最大字號
'unit' => 'pt', //字號單位,可以是pt、px、em或%
'number' => 45, //顯示個數
'format' => 'flat',//列表格式,可以是flat、list或array
'separator' => "\n", //分隔每一項的分隔符
'orderby' => 'name',//排序字段,可以是name或count
'order' => 'ASC', //升序或降序,ASC或DESC
'exclude' => null, //結果中排除某些標籤
'include' => null, //結果中只包含這些標籤
'link' => 'view' //taxonomy鏈接,view或edit
'taxonomy' => 'post_tag', //調用哪些分類法作爲標籤雲
);
$return = array_merge( $args, $newargs);
return $return;
}