wp_tag_cloud

Definition:
function wp_tag_cloud( $args = '' ) {}

Display tag cloud.
The text size is set by the ‘smallest’ and ‘largest’ arguments, which will use the ‘unit’ argument value for the CSS text size unit. The ‘format’ argument can be ‘flat’ (default), ‘list’, or ‘array’. The flat value for the ‘format’ argument will separate tags with spaces. The list value for the ‘format’ argument will format the tags in a UL HTML list. The array value for the ‘format’ argument will return in PHP array type format.

Parameters

  • array|string $args: Optional. Override default arguments.

Return values

returns:Generated tag cloud, only if no failures and ‘array’ is set for the ‘format’ argument.

Defined filters

  • wp_tag_cloud
    apply_filters( 'wp_tag_cloud', $return, $args )

Source code

function wp_tag_cloud( $args = '' ) {

	$defaults = array(

		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,

		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',

		'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true

	);

	$args = wp_parse_args( $args, $defaults );



	$tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags



	if ( empty( $tags ) || is_wp_error( $tags ) )

		return;



	foreach ( $tags as $key => $tag ) {

		if ( 'edit' == $args['link'] )

			$link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );

		else

			$link = get_term_link( intval($tag->term_id), $tag->taxonomy );

		if ( is_wp_error( $link ) )

			return false;



		$tags[ $key ]->link = $link;

		$tags[ $key ]->id = $tag->term_id;

	}



	$return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args



	$return = apply_filters( 'wp_tag_cloud', $return, $args );



	if ( 'array' == $args['format'] || empty($args['echo']) )

		return $return;



	echo $return;

}

4155

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: