Head in the clouds
Posted on Tuesday, 19 February 2008 07:14I wanted to create a tag cloud, and looked at Cal Evans's Cloud Generator, which to me seemed overly complex, though very stable I'm sure. I just thought that it would be easier to work it out myself and tailor the solution to my needs.
It was actually easier to do than I thought.
- I run a query against the top 20 tags, returning the tag name, and usage tally, ordered alphabetically.
- I loop the results, adding them to two separate arrays, and calculate the maximum usage and minimum usage.
- Now I have the maximum usage value, I calcululate each usage as a percentage of the maximum, which I use to give the tag a rank 1-5. 0% - 19% is rank 1, 20% - 39% is rank 2 and so on.
- The tag is output as <span class="tag_rank_1"><a href="tagurl">Tag Name</a></span>
- In the stylesheet I set the styles I want for each rank such as darkening and enlargement of the font.
Click here for the source code.