bb_get_tag_heat_map

The BuddyPress bb get tag heat map function.

Description

bb_get_tag_heat_map( $tags, (string) $args = '' ); 

Parameters (2)

0. $tags
The tags.
1. $args — Optional. (string) => ''
The args.

Usage

  1. if ( !function_exists( 'bb_get_tag_heat_map' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php'; 
  3.  
  4. // The tags. 
  5. $tags = null; 
  6.  
  7. // The args. 
  8. $args = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_get_tag_heat_map($tags, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-template.php  
  1. function bb_get_tag_heat_map( $tags, $args = '' ) { 
  2. $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'limit' => 45, 'format' => 'flat' ); 
  3. $args = wp_parse_args( $args, $defaults ); 
  4. extract($args, EXTR_SKIP); 
  5.  
  6. if ( !$tags ) 
  7. return; 
  8.  
  9. foreach ( (array) $tags as $tag ) { 
  10. $counts{$tag->raw_tag} = $tag->tag_count; 
  11. $taglinks{$tag->raw_tag} = bb_get_tag_link( $tag ); 
  12.  
  13. $min_count = min($counts); 
  14. $spread = max($counts) - $min_count; 
  15. if ( $spread <= 0 ) 
  16. $spread = 1; 
  17. $fontspread = $largest - $smallest; 
  18. if ( $fontspread <= 0 ) 
  19. $fontspread = 1; 
  20. $fontstep = $fontspread / $spread; 
  21.  
  22.  
  23. $a = array(); 
  24.  
  25. foreach ( $counts as $tag => $count ) { 
  26. $taglink = esc_attr($taglinks{$tag}); 
  27. $tag = str_replace(' ', ' ', esc_html( $tag )); 
  28. $fontsize = round( $smallest + ( ( $count - $min_count ) * $fontstep ), 1 ); 
  29. $a[] = "<a href='$taglink' title='" . esc_attr( sprintf( __('%d topics'), $count ) ) . "' rel='tag' style='font-size:$fontsize$unit;'>$tag</a>"; 
  30.  
  31. switch ( $format ) : 
  32. case 'array' : 
  33. $r =& $a; 
  34. break; 
  35. case 'list' : 
  36. $r = "<ul class='bb-tag-heat-map'>\n\t<li>"; 
  37. $r .= join("</li>\n\t<li>", $a); 
  38. $r .= "</li>\n</ul>\n"; 
  39. break; 
  40. default : 
  41. $r = join("\n", $a); 
  42. break; 
  43. endswitch; 
  44.  
  45. return apply_filters( 'bb_get_tag_heat_map', $r, $tags, $args );