描述
在所谓的“标签云”中输出标签列表,其中每个标签的大小由特定标签分配给文章的次数决定。
参数
- $args
- 
(array|string)(可选) 用于显示标签云的参数数组或字符串。有关可以在 $args中传递的参数的完整列表,请参见wp_generate_tag_cloud()和get_terms()。- 'number'
 (int) 要显示的标签数。接受任何正整数或零以返回全部。默认值45。
- 'link'
 (string) 显示term编辑链接还是term固定链接。接受'edit'和'view'。默认值'view'。
- 'post_type'
 (string) 文章类型。用于突出显示链接编辑页面上的适当文章类型菜单。默认为与分类相关联的第一个文章类型。
- 'echo'
 (bool) 是输出结果还是返回结果。默认为true。
 默认值: '' 
- 'number'
返回
(void|string|string[]) 如果'echo'参数为true,或失败时,则无返回。否则,根据'format'参数,将标签云作为字符串或数组返回。
源码
更新日志
| 版本 | 描述 | 
|---|---|
| 4.8.0 | 添加了 show_count参数。 | 
| 2.8.0 | 添加了 taxonomy参数。 | 
| 2.3.0 | 开始引入 | 
使用示例
- 云的大小有限,并按数量而不是名称排序 - <?php wp_tag_cloud( 'smallest=15&largest=40&number=50' ); ?> 
- 显示类别和标签云 - 使用taxonomy参数的数组功能可以显示类别和标签云。 - <?php $args = array( 'taxonomy' => array( 'post_tag', 'category' ), ); wp_tag_cloud( $args ); ?> 
- 在“热门标签”标题下显示云 - <?php if ( function_exists( 'wp_tag_cloud' ) ) : ?> <h2>Popular Tags</h2> <ul> <li><?php wp_tag_cloud( 'smallest=8&largest=22' ); ?></li> </ul> <?php endif; ?> 
- 云返回为数组,但未显示 - 变量$tag将包含用于其他PHP代码的标签云 - <?php $tag = wp_tag_cloud( 'format=array' ); ?> 
- 显示类别云 - 使用taxonomy参数可以显示类别云。 - <?php wp_tag_cloud( array( 'taxonomy' => 'category' ) ); ?> 
- 更改云链接的标题文本 - 使用topic_count_text_callback参数传入新的回调函数。原始函数default_topic_count_text()位于/wp-includes/category-template.php中。本例将标题文本从默认的“topics”更改为“pictures”。 - <?php wp_tag_cloud( array( 'topic_count_text_callback' => 'my_tag_text_callback' ) ); function my_tag_text_callback( $count ) { return sprintf( _n( '%s picture', '%s pictures', $count ), number_format_i18n( $count ) ); } ?>
