标签云widget不仅能展示标签,还能展示目录,或自定义的分类方法。默认情况是用不同字号反映标签热度(文章多少),英文字号一般偏小,若字号不合适,可通过程序调整。
WP默认的widget通常会提供更改参数的filter
WordPress的小工具大多提供修改参数的filter,允许我们在不修改核心代码的情况下做简单改动。
WordPress默认的widget在wp-includes/defalt-widgets.php中
修改标签云widget的参数要用filter: widget_tag_cloud_args
方法如下,代码放在主题的functions.php中即可
/* Change the font size of wp tag cloud */
add_filter( 'widget_tag_cloud_args', 'theme_tag_cloud_args' );
function theme_tag_cloud_args( $args ){
$args['smallest'] = 12;
$args['orderby'] = 'count';
$args['order'] = 'DESC';
return $args
}通过这段代码,将标签云中最小的字号设置为12pt,且标签按照文章数量由多到少排序。
如果你要修改很多参数…
下面这段代码列出了大部分参数,修改自己需要的即可。
/* Change the font size of wp 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, //结果中不包含指定的taxonomy
'include' => null, //结果中只包含这些taxonomy
'link' => 'view' //taxonomy链接,view或edit
);
$return = array_merge( $args, $newargs);
return $return;
}