SHARE
TWEET

SB tag cloud fix: NEW sb_print_tag_clouds

bhengh Jul 17th, 2013 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Prints tag cloud
  2. function sb_print_tag_clouds($minfont=80, $maxfont=150) {
  3.         global $wpdb;
  4.         $rawtags = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_tags as t RIGHT JOIN {$wpdb->prefix}sb_sermons_tags as st ON t.id = st.tag_id");
  5.         foreach ($rawtags as $tag) {
  6.                 if (isset($cnt[$tag->name]))
  7.                         $cnt[$tag->name]++;
  8.                 else
  9.                         $cnt[$tag->name] = 1;
  10.         }
  11.         unset($cnt['']);
  12.         $fontrange = $maxfont - $minfont;
  13.         $maxcnt = 0;
  14.         $mincnt = 1000000;
  15.         foreach ($cnt as $cur) {
  16.                 if ($cur > $maxcnt) $maxcnt = $cur;
  17.                 if ($cur < $mincnt) $mincnt = $cur;
  18.         }
  19.         $cntrange = $maxcnt + 1 - $mincnt;
  20.         $minlog = log($mincnt);
  21.         $maxlog = log($maxcnt);
  22.         $logrange = $maxlog == $minlog ? 1 : $maxlog - $minlog;
  23.         arsort($cnt);
  24.         foreach ($cnt as $tag => $count) {
  25.                 $size = $minfont + $fontrange * (log($count) - $minlog) / $logrange;
  26.                 $out[] = '<a style="font-size:'.(int) $size.'%" href="'.sb_get_tag_link($tag, FALSE).'">'.$tag.'</a>';
  27.         }
  28.         echo implode(' ', $out);
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top