523
528
function wp_tag_cloud( $args = '' ) {
524
529
$defaults = array(
525
530
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
526
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
531
'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
527
532
'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
529
534
$args = wp_parse_args( $args, $defaults );
575
591
* 'format' argument will format the tags in a UL HTML list. The array value for
576
592
* the 'format' argument will return in PHP array type format.
578
* The 'tag_cloud_sort' filter allows you to override the sorting done
579
* by the 'orderby' argument; passed to the filter: $tags array and $args array.
594
* The 'tag_cloud_sort' filter allows you to override the sorting.
595
* Passed to the filter: $tags array and $args array, has to return the $tags array
581
598
* The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
582
599
* The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or
599
616
global $wp_rewrite;
600
617
$defaults = array(
601
618
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
602
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
619
'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
603
620
'topic_count_text_callback' => 'default_topic_count_text',
621
'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
607
624
if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
608
625
$body = 'return sprintf (
609
_n('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count),
626
_n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
610
627
number_format_i18n( $count ));';
611
628
$args['topic_count_text_callback'] = create_function('$count', $body);
614
631
$args = wp_parse_args( $args, $defaults );
616
632
extract( $args );
618
634
if ( empty( $tags ) )
621
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
622
if ( 'name' == $orderby )
623
uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
625
uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
627
$tags = apply_filters( 'tag_cloud_sort', $tags, $args );
629
if ( 'DESC' == $order )
630
$tags = array_reverse( $tags, true );
631
elseif ( 'RAND' == $order ) {
632
$keys = (array) array_rand( $tags, count( $tags ) );
634
foreach ( $keys as $key )
635
$temp[$key] = $tags[$key];
637
$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
638
if ( $tags_sorted != $tags ) { // the tags have been sorted by a plugin
639
$tags = $tags_sorted;
642
if ( 'RAND' == $order ) {
645
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
646
if ( 'name' == $orderby )
647
uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
649
uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
651
if ( 'DESC' == $order )
652
$tags = array_reverse( $tags, true );
642
656
if ( $number > 0 )
643
657
$tags = array_slice($tags, 0, $number);
645
659
$counts = array();
646
foreach ( (array) $tags as $key => $tag )
647
$counts[ $key ] = $tag->count;
660
$real_counts = array(); // For the alt tag
661
foreach ( (array) $tags as $key => $tag ) {
662
$real_counts[ $key ] = $tag->count;
663
$counts[ $key ] = $topic_count_scale_callback($tag->count);
649
666
$min_count = min( $counts );
650
667
$spread = max( $counts ) - $min_count;
660
$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
662
677
foreach ( $tags as $key => $tag ) {
663
678
$count = $counts[ $key ];
679
$real_count = $real_counts[ $key ];
664
680
$tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
665
681
$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
666
682
$tag_name = $tags[ $key ]->name;
667
$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $count ) ) . "'$rel style='font-size: " .
683
$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $real_count ) ) . "' style='font-size: " .
668
684
( $smallest + ( ( $count - $min_count ) * $font_step ) )
669
685
. "$unit;'>$tag_name</a>";
912
929
* @param string $after Optional. After list.
913
930
* @return null|bool False on WordPress error. Returns null when displaying.
915
function the_terms( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
916
$return = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
917
if ( is_wp_error( $return ) )
932
function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
933
$term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
935
if ( is_wp_error( $term_list ) )
938
echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after);