如何修改WordPress自带标签云小工具的显示参数

有些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;
}

如果你想了解参数的详情,请访问 WordPress函数:wp_tag_cloud(标签云)

如果你要制作一个彩色标签云,可以参考 WordPress添加彩色标签云

还可以继续阅读:添加数量和排序选项到WordPress标签云小工具

来源:

https://www.wpdaxue.com/custom-tag-cloud-widget.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32765.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?