pf » How To Make a Tag Cloud
How To Make a Tag Cloud

Jeffery Zeldman proclaims that tag clouds are the new mullets. However, as I'm sure you're aware some people just can't resist the mullet.
I actually find my tag cloud quite handy because it lists all my tags on one page, and I can see what topics I post about most frequently quite easily. I also use it as a way to see which tags I have already used, so I can be consistent when tagging posts.
Anyways a lot of folks would like to know just how you can get one of these mullets, er tag clouds. I have shown how I do it below using CFML. If you don't use ColdFusion you should still be able to follow along.
At this point you may be wondering what's a tag cloud? If so consult the picture below:
Ok, now let the mullets reign...
Step 1 - Get a list tags, and their frequency
<cfquery datasource="#dsn#" name="tags"> SELECT COUNT(tag) AS tagCount, tag FROM tblblogtags GROUP BY tag </cfquery>
In my tag cloud I list all my tags, but if you have a lot of tags you may want to limit the min number of occurrences using a HAVING statement. For example HAVING tagCount > 5
Step 2 - Find the Max and Min frequency
<cfset tagValueArray = ListToArray(ValueList(tags.tagCount))> <cfset max = ArrayMax(tagValueArray)> <cfset min = ArrayMin(tagValueArray)>
Step 3 - Find the difference between max and min, and the distribution
<cfset diff = max - min> <cfset distribution = diff / 3>
You can define the distribution to be more granular if you like by dividing by a larger number, and using more font sizes below. You will probably need to play with this to get your tag cloud to look good.
Step 4 - Loop over the tags, and output with size
<cfoutput query="tags"> <cfif tags.tagCount EQ min> <cfset class="smallestTag"> <cfelseif tags.tagCount EQ max> <cfset class="largestTag"> <cfelseif tags.tagCount GT (min + (distribution*2))> <cfset class="largeTag"> <cfelseif tags.tagCount GT (min + distribution)> <cfset class="mediumTag"> <cfelse> <cfset class="smallTag"> </cfif> <a href="/tag/#tags.tag#" class="#class#">#tags.tag#</a> </cfoutput>
Step 5 - add css classes to your stylesheet
.smallestTag { font-size: xx-small; }
.smallTag { font-size: small; }
.mediumTag { font-size: medium; }
.largeTag { font-size: large; }
.largestTag { font-size: xx-large; }
There are probably lots of different ways to build a tag cloud, but this is the first method that came to mind.
add to del.icio.us
| Tags: tags, blog, tagging, folksonomy, tag cloud, cfml, tips
Related Entries
- Make your blog better with tags - October 14, 2005
- Increase Productivity with Action Tagging - August 1, 2005
- Some del.icio.us Tips - June 16, 2005
- Related Posts - April 8, 2005
- Visualization of my del.icio.us tags - April 24, 2006
- Profile: TagCloud TechCrunch
- DIY Tag Cloud Library clips
- Tag Cloud per AVBlog Andrea Veggiani - Blog personale
- TagClouds Obervations, font sizes and colors ? 3spots ? ? ?
- BRAND TAG CLOUDS Population Statistic
- How To Make a Tag Cloud ????????? ??
thanks alot for posting this, along with some code... much appreciated ;)
/foO
it's an auto-folksonomy tool built using the Term Extraction APIS. It combines Ajax with Folksonomies and Yahoo Web Services to allow you to search on RSS feeds, News, Movies, Images or just obtain the original story, all without a page-refresh.
Would love to get some feedback on it or suggestions for improvement. regards, -fs
I need to implement this on my site www.similarthings.com :) Minus the mullet!
Did you sign up? You should check it out, I have added some nice Ajax and Effects to some of the admin.
I did the font sizing a bit differently, but it's the same basic premise.
The task I'm working on now, however is: How would one add the capability to display at least one tag for every letter of the alphabet?
Assume for a second that you have 5500 tags in your tag table. That's alot of tags to display - so what I would want to do is find enough tags to fill out a max of 100 tags, for instance, with at least one tag from each letter of the alphabet. (otherwise, you might have the first 100 tags be A-G, rather than A-Z...looks strange to users, and skips cool content in the H-Z range)
Anyway, tags are cool, and thanks for the ideas!!
I used your ideas here: http://www.rel8r.com/tags/
i loved the idea of having my own tag cloud. i tried eurekstr and zoomcloud but this seems like a better idea.
I tried cutting an pasting this in my template under the sidebar section and I get no results. I also tried adding <script> and </script> after now the #tag thingies disappear but there is no tag cloud.
I know that I doing something wrong. I hope it is simple and I hope you can help.
Thanks!
I was just talking with a friend about how to create a tag cloud for my blog but I wasn't sure how to go about it.
Although I don't use ColdFusion, your article was (as you said!) easy enough to follow. I'm going to get to work on creating my own tag cloud today! (I use WordPress as my blogging engine so I guess I'll be writing my code in PHP as a plugin.
Thanks for this helpful article!
http://en.dahnielson.com/2006/07/blog-overcast-tagclouds.html
http://www.ArticleOnRamp.com/Tag-Cloud.cfm
Thanks!
Some of my questions:
Are they only or mainly used for blogs?
What kind of tags do I use to link the key words with the tag link generator (tag cloud links I supose).
Does the above script goes in the head or the body of the page.
As you can understand I am completely lost. Thank you all in advance
http://www.8coupons.com
http://www.taskfly.com/blog/?p=6
We have added a little bit "colors" to the final styling (selected a main color and blended it).
http://mgk1969.wordpress.com/2007/03/23/making-a-tag-cloud-in-coldfusion/
Many regards, exl
Do you think that I can implement this tag clouds on my html website? http://www.jocuri.pe-net.info or it's working only on php sites,
Thank you
http://blogs.dekoh.com/dev/2007/10/29/choosing-a-good-font-size-variation-algorithm-for-your-tag-cloud/
With this mod, I had a working tag cloud in about 15 minutes. Thanks a lot!
However, Im sure there are advantages to having a mullet...like keeping your neck warm!
1: as someone said elsewhere, all tutorials seems to assume you know how to populate your database, and
2: all the techniques i've seen assume one has a fresh site to which one can start adding tags for articles/pages with each added article/page from scratch.
But what can be done for sites which already have tens of thousands of pages of content in database and where it is impossible to add tags for each of these articles because it would take forever?
Secondly i dont understand how the tags sizes in your tag-cloud relate to anything at all (such as number of pages using the word)? because each tag simply links to one page, and I can't see any relationship between tag size and anything which loads when one clicks a tag (?)
Also this assumes one's site loads pages based on a single word at the end of the address-string, so how would one do this for sites where content page links require full link addresses rather than the tag-word itself?
Simply put, i couldnt find a single decent documented page on this subject for beginners anywhere on the www in 6 hours of searching, which is quite incredible given tag-cloud popularity. All articles assume the user knows a hell of a lot already. But this is a general shortcoming of most computer peoples' tutorials online - they are good at coding but hopeless at understanding the principals of teaching a subject. There is simply no real explanations at all given with this tutorial although i realise this may not have been made for beginners.
One question though, how do you recommend dealing with multiple tags for an entry? I initially set up a test DB Table that had a "tag" field with multiple tags separated by a comma, obviously this code wasn't able to break up the list into various keywords, and simply grouped them all into one big tag. Looking through it I don't really see how it could be modified to deal with a list.
Is having a separate tags table that is then linked back to the master record the answer? That seems like the only plausible way, as having only one tag per record seems very limiting.
http://pastebin.com/f1d04c178
And, for those asking about the db table, it should look something like.. (Here's to hoping it lines up..)
+---------+-------------+ | Field | Type | +---------+-------------+ | id | numeric | | tag | varchar | +---------+-------------+
- ColdFusion 8 FCKeditor Vulnerability
- Ajax Same Origin Policy No More with Firefox 3.5
- Firefox 3.5 Introduces Origin Header, Security Features
- Tips for Secure File Uploads with ColdFusion
- 7 Years And Blog Entry Number 700
- CFCatch Java Exceptions
- Cheat Sheet for SQL Server
- CFML on Google App Engine for Java
RSS


Pete Freitag is a software engineer, and web developer located in










