jayminkapish - Jaymin Patel, Wordpress Developer, New York
Subscribe to jayminkapish RSS Friend Jaymin Patel on Facebook Follow Jaymin Patel on Twitter

« Go to home page

WordPress: Calculate font-size in Tag Cloud

$fontSizeUnits = "px";
$fontSizeMin = 15;
$fontSizeMax = 50;
$maxValue = 12;
$minValue = 1;

where $results is MySQL result set.

foreach ($results as $result) {
$tag = $result->name;
$tagURI = get_option('home') . '/' . $result->taxonomy . '/' . $result->slug . '/';
$count = $result->count;
$weight = ( $count - $minValue ) / ( $maxValue - $minValue );
$fontSize = $fontSizeMin + round( ($fontSizeMax - $fontSizeMin) * $weight );
echo "<li style='display: inline-block; font-size:". $fontSize. $fontSizeUnits."'><a href=".$tagURI." title='(".$count." posts)'>".$tag."</a></li>";
}


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


About

Wordpress Work

Plugins I like

Recent Posts

Wordpress News

Blogroll

Connect

I am excited about