wp_tag_cloud()显示标签云

目录

描述

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() 用法

参数

smallest

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

默认值: 8

largest

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

默认值: 22

unit

(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'

number

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

默认值: 45

format

(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

separator

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

默认值: '
' (whitespace)

orderby

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

  • 'name'
  • 'count'

默认值: name

order

(string) (可选) Sort order.

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

默认值: ASC

exclude

(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

include

(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

topic_count_text_callback

(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

link

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

  • 'view'
  • 'edit'

默认值: view

taxonomy

(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

echo

(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() 源文件

相关