iXiNX Club主要为自用型文档社区,同时也开放共用文档,欢迎爱好者加入并共享内容,翻译文档
iXiNX Club开放性测试进行中,欢迎体验反馈,如有任何问题均可联系管理员
LV2
更改标签云中的标签数量
将此代码添加到子主题的文件中,或通过允许添加自定义函数的插件(例如Code snippets插件)添加。避免将自定义代码直接添加到父主题的文件中,因为当您更新主题时,这将被完全擦除。functions.php

最新的 WordPress 版本

代码: 全选

add_filter( 'wp_generate_tag_cloud_data', 'tie_custom_code_tag_cloud_blocks' );
function tie_custom_code_tag_cloud_blocks( $tags_data ){

	if( ! empty( $tags_data ) ){
		array_splice( $tags_data, 15 );
	}

	return $tags_data;
}
旧的 WordPress 版本

代码: 全选

/*
 * Change the number of tags in the Tag Cloud Widget
 */
add_filter( 'widget_tag_cloud_args', 'tie_custom_code_tag_cloud', 20 );
function tie_custom_code_tag_cloud( $args ){

	if( isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag' ){
		$args['number'] = 15;
	}

	return $args;
}

信息