tag cloud

<code>
function printTagCloud($tags) {
        // $tags is the array
       
        arsort($tags);
       
        $max_size = 32; // max font size in pixels
        $min_size = 12; // min font size in pixels
       
        // largest and smallest array values
        $max_qty = max(array_values($tags));
        $min_qty = min(array_values($tags));
       
        // find the range of values
        $spread = $max_qty - $min_qty;
        if ($spread == 0) { // we don’t want to divide by zero
                $spread = 1;
        }
       
        // set the font-size increment
        $step = ($max_size - $min_size) / ($spread);
       
        // loop through the tag array
        foreach ($tags as $key => $value) {
                // calculate font-size
                // find the $value in excess of $min_qty
                // multiply by the font-size increment ($size)
                // and add the $min_size set above
                $size = round($min_size + (($value - $min_qty) * $step));
       
                echo ‘<a href=”#” style=”font-size: ‘ . $size . ‘px” title=”‘ . $value . ‘ things tagged with ‘ . $key . ‘”>’ . $key . ‘</a> ‘;
        }
}

$tags = array(‘weddings’ => 32, ‘birthdays’ => 41, ‘landscapes’ => 62, ‘ham’ => 51, ‘chicken’ => 23, ‘food’ => 91, ‘turkey’ => 47, ‘windows’ => 82, ‘apple’ => 27);

printTagCloud($tags);
</code>

Rating: 9.3/10 (3 votes cast)

Related posts:

  1. wpmu array_merge() error for array when you twist wpmu, sometime plugin does not work well...
  2. wordpress similar posts error fix if you get an error like this when you turn...
  3. SAS小程序:从Yahoo.com下载股票行情数据到SAS数­据集 SAS小程序:从Yahoo.com下载股票行情数据到SAS数­据集 /* 从yahoo.com读取股票行情数据*/ %macro quotes (code=, start=, end=, prompt=NO); %local...
  4. Call to undefined function: wp_register_sidebar_widget()’ error if your wpmu plugin is using wp_register_sidebar_widget(), then you will...

Leave a Reply

Preview:

Tags:
Separate individual tags by commas