[wp-trac] [WordPress Trac] #21198: Add tag id to callback to allow customizing of the tooltip text in tag clouds

WordPress Trac wp-trac at lists.automattic.com
Mon Jul 9 03:01:57 UTC 2012


#21198: Add tag id to callback to allow customizing of the tooltip text in tag
clouds
-----------------------------+-----------------------------
 Reporter:  najamelan        |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  General          |    Version:
 Severity:  minor            |   Keywords:
-----------------------------+-----------------------------
 When hovering over tags in tag clouds wp shows the number of posts. To
 achieve this a callback is called with the number. This callback forms the
 text to be added to the title attribute.

 The callback can be set by the user, but because it only gets the count,
 and not the tag id, not much can be done.

 With the tag id the callback could for example return the tag description
 for the tooltip.

 Not much is needed for this since the tag id is available in the context
 of the caller. A 2 line patch to wp-includes/category-template.php
 provides this functionality.

 This is a patch generated by Git on the 3.4.1 code.

 Subject: [PATCH] wp-includes/category-template: add tagid to call for
 tooltip
  text in tag clouds

 {{{
 ---
  wp-includes/category-template.php |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

 diff --git a/wp-includes/category-template.php b/wp-includes/category-
 template.php
 --- a/wp-includes/category-template.php
 +++ b/wp-includes/category-template.php
 @@ -559,7 +559,7 @@ function wp_tag_cloud( $args = '' ) {
   * @param integer $count number of posts with that tag
   * @return string text for the tooltip of a tag link.
   */
 -function default_topic_count_text( $count ) {
 +function default_topic_count_text( $count, $tag_id ) {
         return sprintf( _n('%s topic', '%s topics', $count),
 number_format_i18n( $count ) );
  }

 @@ -671,7 +671,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) {
                 $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: " .
 +               $a[] = "<a href='$tag_link' class='tag-link-$tag_id'
 title='" . esc_attr( call_user_func( $topic_count_text_callback,
 $real_count, $tag_id ) ) . "' style='font-size: " .
                         str_replace( ',', '.', ( $smallest + ( ( $count -
 $min_count ) * $font_step ) ) )
                         . "$unit;'>$tag_name</a>";
         }
 --
 }}}


 Probably it would be desirable some day to replace the callback by a
 filter for consistency, but this works fine and probably has less
 overhead.

 Thanks alot

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21198>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list