WordPress.org

Make WordPress Core

Changeset 11894


Ignore:
Timestamp:
09/01/2009 08:06:11 PM (9 years ago)
Author:
azaozz
Message:

Logarithmic scale for tag cloud, props kometbomb, fixes #10703

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r11838 r11894  
    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 *
     
    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
     
    642653
    643654    $counts = array();
    644     foreach ( (array) $tags as $key => $tag )
    645         $counts[ $key ] = $tag->count;
     655    $real_counts = array(); // For the alt tag
     656    foreach ( (array) $tags as $key => $tag ) {
     657        $real_counts[ $key ] = $tag->count;
     658        $counts[ $key ] = $topic_count_scale_callback($tag->count);
     659    }
    646660
    647661    $min_count = min( $counts );
     
    660674    foreach ( $tags as $key => $tag ) {
    661675        $count = $counts[ $key ];
     676        $real_count = $real_counts[ $key ];
    662677        $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
    663678        $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
    664679        $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: " .
     680        $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $real_count ) ) . "'$rel style='font-size: " .
    666681            ( $smallest + ( ( $count - $min_count ) * $font_step ) )
    667682            . "$unit;'>$tag_name</a>";
Note: See TracChangeset for help on using the changeset viewer.