Wednesday 25 March 2009

Tag cloud formula

Modified the tag cloud for photo categories using a neat formula adapted from that found at http://r2soft.blogspot.com/2007/12/how-to-create-tag-cloud-with-formula.html

Choose a $lower_threshold then select tag counts having count of $lower_threshold or more. Find the highest tag count and define largest and smallest font size.
$cloudnumber=round(( (($this_tag_count-$lower_threshold) *
($largest_font_size-$smallest_font_size)) /
($most_popular_tag_count-$lower_threshold) )
+ $smallest_font_size);
if ($cloudnumber<0) { $cloudnumber=0; }

I put the clouds into 6 discrete buckets defined by CSS - ('cloud'.$cloudnumber) cloud0, cloud1, cloud2 etc. then modify the characteristics of the buckets. Could make it a more continuous variation in font size using a range of 75% to 300% which seems popular but I like the look of the fixed buckets generated by the $cloudnumber.

Altering the $lower_threshold will help to limit the number of tags on the photographs screen. Probably, in due course, add a 'more' link which will go to an alternative screen where the $lower_threshold is set to 1.

No comments:

Post a Comment