Make WordPress Core

Ticket #10703: logarithmic_tag_cloud.diff

File logarithmic_tag_cloud.diff, 2.1 KB (added by kometbomb, 14 years ago)

Added callback, fixed the alt tag

  • wp-includes/category-template.php

     
    566566}
    567567
    568568/**
     569 * Default topic count scaling for tag links
     570 *
     571 * @param integer $count number of posts with that tag
     572 * @return integer scaled count
     573 */
     574function default_topic_count_scale( $count ) {
     575        return round(log10($count + 1) * 100);
     576}
     577
     578
     579/**
    569580 * Generates a tag cloud (heatmap) from provided data.
    570581 *
    571582 * The text size is set by the 'smallest' and 'largest' arguments, which will
     
    602613                'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
    603614                'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
    604615                'topic_count_text_callback' => 'default_topic_count_text',
    605                 'filter' => 1,
     616                'filter' => 1, 'topic_count_scale_callback' => 'default_topic_count_scale'
    606617        );
    607618
    608619        if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
     
    641652                $tags = array_slice($tags, 0, $number);
    642653
    643654        $counts = array();
     655        $real_counts = array(); // For the alt tag
    644656        foreach ( (array) $tags as $key => $tag )
    645                 $counts[ $key ] = $tag->count;
     657        {
     658                $real_counts[ $key ] = $tag->count;
     659                $counts[ $key ] = $topic_count_scale_callback($tag->count);
     660        }
    646661
    647662        $min_count = min( $counts );
    648663        $spread = max( $counts ) - $min_count;
     
    659674
    660675        foreach ( $tags as $key => $tag ) {
    661676                $count = $counts[ $key ];
     677                $real_count = $real_counts[ $key ];
    662678                $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
    663679                $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
    664680                $tag_name = $tags[ $key ]->name;
    665                 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $count ) ) . "'$rel style='font-size: " .
     681                $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $real_count ) ) . "'$rel style='font-size: " .
    666682                        ( $smallest + ( ( $count - $min_count ) * $font_step ) )
    667683                        . "$unit;'>$tag_name</a>";
    668684        }