wp_generate_tag_cloud [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Generates a tag cloud (heatmap) from provided data.
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.
The 'tag_cloud_sort' filter allows you to override the sorting. Passed to the filter: $tags array and $args array, has to return the $tags array after sorting it.
The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or 'RAND'.
The 'number' argument is how many tags to return. By default, the limit will be to return the entire tag cloud list.
The 'topic_count_text_callback' argument is a function, which given the count of the posts with that tag returns a text for the tooltip of the tag link.
Source
<?php
function wp_generate_tag_cloud( $tags, $args = '' ) {
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
'topic_count_text_callback' => 'default_topic_count_text',
'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
);
if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
$body = 'return sprintf (
_n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
number_format_i18n( $count ));';
$args['topic_count_text_callback'] = create_function('$count', $body);
}
$args = wp_parse_args( $args, $defaults );
extract( $args );
if ( empty( $tags ) )
return;
$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
if ( $tags_sorted != $tags ) { // the tags have been sorted by a plugin
$tags = $tags_sorted;
unset($tags_sorted);
} else {
if ( 'RAND' == $order ) {
shuffle($tags);
} else {
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
if ( 'name' == $orderby )
uasort( $tags, '_wp_object_name_sort_cb' );
else
uasort( $tags, '_wp_object_count_sort_cb' );
if ( 'DESC' == $order )
$tags = array_reverse( $tags, true );
}
}
if ( $number > 0 )
$tags = array_slice($tags, 0, $number);
$counts = array();
$real_counts = array(); // For the alt tag
foreach ( (array) $tags as $key => $tag ) {
$real_counts[ $key ] = $tag->count;
$counts[ $key ] = $topic_count_scale_callback($tag->count);
}
$min_count = min( $counts );
$spread = max( $counts ) - $min_count;
if ( $spread <= 0 )
$spread = 1;
$font_spread = $largest - $smallest;
if ( $font_spread < 0 )
$font_spread = 1;
$font_step = $font_spread / $spread;
$a = array();
foreach ( $tags as $key => $tag ) {
$count = $counts[ $key ];
$real_count = $real_counts[ $key ];
$tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
$tag_name = $tags[ $key ]->name;
$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count ) ) . "' style='font-size: " .
str_replace( ',', '.', ( $smallest + ( ( $count - $min_count ) * $font_step ) ) )
. "$unit;'>$tag_name</a>";
}
switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "<ul class='wp-tag-cloud'>\n\t<li>";
$return .= join( "</li>\n\t<li>", $a );
$return .= "</li>\n</ul>\n";
break;
default :
$return = join( $separator, $a );
break;
endswitch;
if ( $filter )
return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
else
return $return;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp generate tag cloud « WordPress Codex
Description. Returns an HTML string that makes a tag cloud. Usage. <?php wp_generate_tag_cloud( $tags, $args ); ?> Default Usage. <?php $args = array( ...
codex.wordpress.org - #14577 (wp_generate_tag_cloud() font-size generated with comma ...
Hello, the wp_generate_tag_cloud() function in category-template.php was causing me problems since it returned style="font-size: 1,723828em" for example , ...
core.trac.wordpress.org - wp_generate_tag_cloud (WordPress Function) - WPSeek.com
WordPress lookup for wp_generate_tag_cloud, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - Customize Tags Cloud in WordPress | Kana Solution
Jan 8, 2011 ... Inside function wp_generate_tag_cloud (in the same file as function wp_tag_cloud), we have a chance to filter the ordering of the tags beside ...
www.kanasolution.com