The wp_tag_cloud() function displays a list of tags in what is called a 'tag cloud', where the size of each tag is determined by how many times that particular tag has been assigned to posts.

Beginning with Version 2.8, the taxonomy parameter was added so that any taxonomy could be used as the basis of generating the cloud. That means that a cloud for Categories or any other Custom Taxonomies can be presented to visitors.

wp_tag_cloud() 描述


<?php wp_tag_cloud$args ); ?>

Default Usage

The child_of Key is not a direct part of the Array in wp_tag_cloud, but because this function uses wp_parse_args() and get_terms(), you can use all Array Keys used by get_terms()!

By default, the usage shows:

  • smallest - The smallest tag (lowest count) is shown at size 8
  • largest - The largest tag (highest count) is shown at size 22
  • unit - Describes 'pt' (point) as the font-size unit for the smallest and largest values
  • number - Displays at most 45 tags
  • format - Displays the tags in flat (separated by whitespace) style
  • separator - Displays whitespace between tags
  • orderby - Order the tags by name
  • order - Sort the tags in ASCENDING fashion
  • exclude - Exclude no tags
  • include - Include all tags
  • topic_count_text_callback - Uses function default_topic_count_text
  • link - view
  • taxonomy - Use post tags for basis of cloud
  • echo - echo the results

wp_tag_cloud() 用法



(integer) (可选) The text size of the tag with the smallest count value (units given by unit parameter).

默认值: 8


(integer) (可选) The text size of the tag with the highest count value (units given by the unit parameter).

默认值: 22


(string) (可选) Unit of measure as pertains to the smallest and largest values. This can be any CSS length value, e.g. pt, px, em, %.

默认值: 'pt'


(integer) (可选) The number of actual tags to display in the cloud. (Use '0' to display all tags.)

默认值: 45


(string) (可选) Format of the cloud display.

  • 'flat' separated by whitespace defined by 'separator' parameter.
  • 'list' UL with a class of 'wp-tag-cloud'
  • 'array' returns the tag cloud as an array for use in PHP

默认值: flat


(string) (可选) The text/space between tags.

默认值: '
' (whitespace)


(string) (可选) Order of the tags.

  • 'name'
  • 'count'

默认值: name


(string) (可选) Sort order.

  • 'ASC'
  • 'DESC'
  • 'RAND' tags are in a random order.

默认值: ASC


(string) (可选) Comma separated list of tags (term_id) to exclude. For example, exclude=5,27 means tags that have the term_id 5 or 27 will NOT be displayed. Defaults to exclude nothing.

默认值: null


(string) (可选) Comma separated list of tags (term_id) to include. For example, include=5,27 means tags that have the term_id 5 or 27 will be the only tags displayed. Defaults to include everything.

默认值: null


(string) (可选) The function, which, given the count of the posts with that tag, returns a text for the tooltip of the tag link.

默认值: default_topic_count_text


(string) (可选) Set link to allow edit of a particular tag.

  • 'view'
  • 'edit'

默认值: view


(string or array) (可选) Taxonomy or array of taxonomies to use in generating the cloud.

  • 'post_tag'
  • 'category'
  • 'link_category'
  • 'any other registered taxonomy'
  • or array of taxonomies Note: this parameter was introduced with Version 3.1

默认值: post_tag


(boolean) (可选) Display the result or return it in a variable. The default is true (display the tag cloud).

  • 1 (true)
  • 0 (false)

默认值: true

wp_tag_cloud() 参数


Cloud displayed under Popular Tags title

Cloud limited in size and ordered by count rather than name

Cloud returned as array but not displayed

The variable $tag will contain the tag cloud for use in other PHP code

Display a Category Cloud

Use the taxonomy argument to cause a cloud of categories to display.

Display a Cloud of Categories and Tags

Use the array feature of the taxonomy argument to cause a cloud of categories and tags to display.

Change Title Text of Cloud Links

Use the topic_count_text_callback argument to pass in a new callback function. The original function default_topic_count_text() is located in /wp-includes/category-template.php This example changes the title text from the default "topics" to "pictures".

wp_tag_cloud() 示例


wp_tag_cloud() 函数的代码位于 wp-includes/category-template.php.

wp_tag_cloud() 源文件