Posted By

browncardigan on 02/08/10


Tagged

tag-clouds


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

NyX


tag cloudin'


 / Published in: PHP
 

URL: http://bettesmidler.com/code/2009-07-15.htm

  1. // data
  2. $cloud = array('etc' => 10, 'awesome' => 5, 'champagne' => 12);
  3.  
  4. // default font sizes
  5. $min_font_size = 13;
  6. $max_font_size = 70;
  7. $minimum_count = min(array_values($cloud));
  8. $maximum_count = max(array_values($cloud));
  9. $spread = $maximum_count - $minimum_count;
  10.  
  11. // so we don't divide by zero
  12. if($spread == 0) {
  13. $spread = 1;
  14. }
  15.  
  16. // print
  17. foreach ($cloud as $tag => $count) {
  18. $size = $min_font_size + ($count - $minimum_count) * ($max_font_size - $min_font_size) / $spread;
  19. echo '<a style="font-size: '. floor($size) . 'px" href="?q=' . $tag . '" title="\'' . $tag . '">' . $tag . '</a> &nbsp; ';
  20. }

Report this snippet  

You need to login to post a comment.