From 97bef9ee665ede5afb91346bce83d92cb4690531 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 1 Sep 2009 20:06:11 +0000 Subject: [PATCH] Logarithmic scale for tag cloud, props kometbomb, fixes #10703 git-svn-id: https://develop.svn.wordpress.org/trunk@11894 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/category-template.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index fde22f4abf..5ab23960b2 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -565,6 +565,17 @@ function default_topic_count_text( $count ) { return sprintf( _n('%s topic', '%s topics', $count), number_format_i18n( $count ) ); } +/** + * Default topic count scaling for tag links + * + * @param integer $count number of posts with that tag + * @return integer scaled count + */ +function default_topic_count_scale( $count ) { + return round(log10($count + 1) * 100); +} + + /** * Generates a tag cloud (heatmap) from provided data. * @@ -602,7 +613,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'topic_count_text_callback' => 'default_topic_count_text', - 'filter' => 1, + 'filter' => 1, 'topic_count_scale_callback' => 'default_topic_count_scale' ); if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { @@ -641,8 +652,11 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { $tags = array_slice($tags, 0, $number); $counts = array(); - foreach ( (array) $tags as $key => $tag ) - $counts[ $key ] = $tag->count; + $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; @@ -659,10 +673,11 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { 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[] = "$tag_name"; }