This site is a self-contained low down on what's going on in my life, what I'm working on, what I'm thinking about, and how I'm feeling about life in general.

Tuesday, 19 February 2008

I 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.

  1. I run a query against the top 20 tags, returning the tag name, and usage tally, ordered alphabetically.
  2. I loop the results, adding them to two separate arrays, and calculate the maximum usage and minimum usage.
  3. 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.
  4. The tag is output as <span class="tag_rank_1"><a href="tagurl">Tag Name</a></span>
  5. 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.



Tags: PHP Tutorial Tags Blog Cloud Stylesheet
Featured Articles
Recent Articles