23 May 2007

How To Make An Awesome Tag Cloud!

I get a lot of emails asking me about the giant tag cloud hanging out at the top of my site. So many, in fact, that I thought it’d be a great idea to make a post out of it, as a bit of a mini-tutorial. So, without further ado, here’s how to get an awesome tag cloud in the New Blogger (formerly Blogger Beta).

(UPDATE 24/08/2007: Obviously there’s no tag cloud up there anymore, since I redesigned the site. I’ve posted a screenshot below of what it used to look like. Click it for a larger version.)

blogger tag cloud

Okay, back to the regularly scheduled tutorial
.

First start a new blog in Blogger. Got one? Cool.

Now, navigate in Blogger to Template > Page Elements (clicking Layout from the Dashboard will get you there, too). You’re looking for the screen that says “Add and Arrange Page Elements.” Now, in the sidebar of this representation of your blog, click “Add a Page Element.” You’ll get a nice pop-up with a ton of options. Click Labels, cause that’s what you want to add, after all. Keep it alphabetical, change the name if you feel like it, and click “Save Changes.”

Save your template.

Now click over to “Edit HTML.” Definitely a good idea to “Download Full Template” here, to be safe, before you start editing the code. I’ll wait.

Backed up? Good. Moving on.

Search through your code for a line that looks exactly like this:

<b:widget id='Label1' locked='false' title='Labels' type='Label'/>
The “title” attribute might be different if you changed it in the step above. Otherwise, this is the line you’re looking for.

Copy all of this code below.
<b:widget id='Label1' locked='false' title='Labels' type='Label'>
<b:includable id='main'>

<div class='widget-content'>
<div id='LabelDisplay'>
</div>
</div>

<script language='javascript' type='text/javascript'>
function zoomStyle() {
var max = 0;
var min = 10000;
<b:loop values='data:labels' var='label'>
if (<data:label.count/> &gt; max)
max = <data:label.count/>;
if (<data:label.count/> &lt; min)
min = <data:label.count/>;
</b:loop>
var display = &quot;";
<b:loop values='data:labels' var='label'>
var delta = <data:label.count/> - min;
var size = 80 + (delta * 100) / (max - min);
display = display + &quot;<span style='font-size:" + size + "%'><a expr:href='data:label.url + "?max-results=100"' style='text-decoration:none;'><data:label.name/></a></span> &quot;;
</b:loop>

obj = document.getElementById(&#39;LabelDisplay&#39;);
obj.innerHTML = display;
}


zoomStyle();
</script>

<b:include name='quickedit'/>
</b:includable>
</b:widget>
And paste it over (on top of, instead of, replacing!) the line you found. Be very careful not to overwrite the </b:section> that will most likely follow it in your template code.

Click preview, and if you’ve done everything properly, you’ll have a sweet tag cloud with links of various sizes based on frequency of occurrence (if your blog is brand new, you’ll need to post in it first to see the code at work).

If you don’t want it in your sidebar, go back to the Page Elements page, and move the widget around to wherever you like (different templates set different limits on this, which can be subverted, but that’s beyond the scope of this tutorial - email me if you want to get hardcore).

Enjoy! Get tagging! Post your results in the comments for all to see!

(Note: The code up there is a modified version of the Multi-style labels widget written up on Hackosphere. Credit where it’s due.)

57 comments:

Calla said...

Merci beaucoup!

of course, the new blog hasn't been posted enough for it to look as cool as yours yet, but many, many thanks for your super instructional tutorial!

Ben A. Johnson said...

you're so helpful. of course, i've already exhausted you with this issue.

also: i don't know how you put that html thing in there, but that's awesome. you should do a blog post on how you did that.

Kevin M. Keating said...

Glad I could share the love!

And Ben, great idea about the html formatting. I'll keep that in mind for the future.

Absinta said...

Thanks for sharing Kevin.
I've already got my TagCloud but tags appear all in the same 'size'....any advice?

kevin m. keating said...

@absinta:

Is it possible you haven't used any of the tags twice?

If you'd like, you can email me your URL and I can take a quick look to see if something sticks out (kevin@frivolousmotion.com).

Thelma said...

super thanks for this! =)

got anything on adding del.icio.us 'save this page' to wordpress...? having the hardest time and the FAQ and forums don't seem to be any help...

boo.

or maybe it's just me. or maybe it's wordpress?

vin said...

Hi,

Is this the same hack :

http://blog-dr.blogspot.com/2007/06/tag-cloud-for-blogger-layout.html

Kevin M. Keating said...

@vin:

Thanks for pointing that site out - as far as I can tell it's the same code, yups - and they link back to this site, ever so subtly, in the final line of the post.

jp 吉平 said...

Sweet! Check me out; it's exactly what I wanted! Muchas gracias!

Kevin M. Keating said...

jp - glad to help! What's your site?

Doomeru Woebashi said...

Thanks for the code, Kevin. This worked great for me!

Ann said...

Hi Kevin, I tried, but got this message:
We were unable to preview your template
Please correct the error below and submit your template again.
More than one widget was found with id: Label1. Widget IDs should be unique.

I wondered whether I should have replaced the line of code.

I'm a bit of a novice at all of this. :)

Kevin M. Keating said...

Ann, yes, you should have replaced the first line of code (the one that begins b:widget id=label1 locked=false...etc).

You'll notice the first line in the code to copy is exactly the same - either way, you can only have this line ONE TIME.

Hope this helps!

Ann said...

Ta. Thx. Only question now is if I want to give my could a title, where do I put that?

Kevin M. Keating said...

If you want a title for your cloud, stick this code right after <b:includable id='main'> :

<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>

Jon said...

Fantastic. This tag cloud works like a charm. Thanks

Adeena said...

Any suggestions or hints on formatting? It worked great in a sidebox, but up top (see http://geekinreallife.blogspot.com/ ) it's looking less fabulous.

Joanne said...

Your tag cloud is totally awesome, haha. It's exactly what I was looking for. I played around with my layouts limits and finally got it to show (and correctly) where I wanted it to.

Thanks sooo much!

LaSandra Brill said...

Thanks for the Awesome Tag Cloud!

Ariel Aharoni said...

Thanks for the tutorial... but I'd like to incorporate a Cloud Widget in my e-commerce homepage that will show the most popular keywords used in the site's search engine. Is this possible?

Does anybody have experience about this?

Any help will be highly appreciated!

You can email me at: arielaharoni(at)electromundo.com

Muskat said...

Thanks a lot. I love my new label cloud and will feed it to grow beautifully :)

Lisa said...

i love it. but i have far too many freaking labels. Is there any way to cut them off?

thanks, Kevin.

Magnetic Mary said...

Hi, thanks for the code! I set it up on my blog and I love it.
http://magneticmary.blogspot.com/

Just one thing. For some reason (I'm using IE...) I can't see any image, just a tiny space and a horizontal scroll bar, under "Search through your code for a line that looks exactly like this:" in your post. I managed to find where to paste the code by reading through the comments though.

Awesome, thanks again.

Magnetic Mary said...

Me again, regarding the image. Seems to be an IE problem (I know, I know... surprise!). The height of the window is too small, you can actually scroll inside and see the line, but badly.

Kevin M. Keating said...

Magnetic Mary: thanks for letting me know about that issue in IE. Glad you were able to figure it out anyway, though!

Lily said...

Hey thanks heaps for the tutorial on tag cloud! You don't know how long I've been searching for this!!

fbriggs said...

I am the developer of www.MakeCloud.com, a new site that simplifies the process of creating a cloud and adding it to a blog or anywhere else. Just give it an RSS feed and it makes the cloud instantly, with no signup required.

http://www.makecloud.com

It works with blogger too.

Joel said...

I used the one from makecloud.com, I tried yours too but I finally squared to makecould.com :)

clyde said...

thanks for this. got it to work just fine. i'd like to limit the returns - i sometimes use tags for humor or something new - but they may be used just once.

any way to limit the returns to either, 1.) display no more than XX tags, or 2.) display tags with only more than X uses ... ?

thanks

Smiler said...

Hi Kevin, I tried to install the code a few times but I keep getting this message:

"Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: The element type "b:section" must be terminated by the matching end-tag ""."

There was no "/b:section" tag below the script to begin with, so I tried putting one in and then it asks for "div" endtag. Help!

Drew Caperton said...

Thanks for this.

ZeNeece said...

This is awesome! I've become rather attached to tag clouds and wanted one for my blog. Thanks for this. You made my day!
The font is a bit small, but other than that I love it. I used it here:
http://blog.zeneece.com/

Oh, and the tutorial was very easy to follow. Thanks for that too! :)

सागर चन्द नाहर said...

it is too good.. can we increase font size?
on my blog its shows too small fonts is Label Cloud.
Thanks

गीतों की महफिल

The Urban Survival Project said...

Thats an awesome bit of code. Really easy to implement and looks great. The instructions for what to copy over seem to have gone a bit awry in your post as you only see a scroll bar, but it was easy enough to figure out you meant copy over the 'Label1' widget line. In my case I created a second tag list called Label2 and changed the title in your code before pasting it over. That way I get both a cloud and a list. See it in action at http://urbansurvivalproject.blogspot.com/

Thanks again

Rizwan

O Jardineiro said...

Thanks a lot! Simply beautiful!
But... I have a question... How you can justify the text in the tag cloud? Just like in your example from http://bp3.blogger.com/_nYL8yRi-mHs/Rs7msgYZbqI/AAAAAAAABFI/Y4AOASn0ELQ/s1600-h/tags.gif ?
Thanks a lot!

Kevin M. Keating said...

I couldn't say 100% for certain because it depends on the rest of the code in your template, but it ought to work to add this bit of code where the other CSS styles are in your template:

#LabelDisplay {
text-align:justify;
}

Hope this helps.

O Jardineiro said...

Thank you, man!
It did help me!

frnz said...

hi! thanks to your post i was able to add a sweet tag cloud to my blog. although i have a couple of observations, if you don't mind. i removed the existing "Label" widget code and replaced it with the new one. i changed the title beforehand, so that might be the cause of that. nwei, thanks a bunch man.

Fiksacje said...

Great!
You should add information, that someone should check "expand widget code" in template html edit window, and thet change the code of the widget which generates labels. But when You do that, it works pretty well!
example: http://fiksacie.blogspot.com/
Thanks a lot!

Anonymous said...

Love it!Thanks!

nass said...

thanx man!

Jaxter said...

hey thanks a lots!!
first of all i love Barack Obama
about this great widget its really working
thanks for sharing

Tutor Itchie said...

Wow! It's good I found your site. I have been experimenting with a number of suggested ways on "how to add Tag Clouds to your Blog." Your instructions were precise and the easiest to follow.

Thank you very much.

Gypsy Thornton said...

Thanks so much! Excellent tutorial that works really well.
Now I have to go check out the other cool things in your blog...
Thanks again! http://theinkgypsy.blogspot.com/

Daniel Smith said...

Kevin,

Just wanted to drop you a line and say that I stumbled across your blog when trying to figure out how to do a dynamic cloud tag, and your post couldn't have been more helpful or precise. With your instructions and help throughout the comments, I had it working on the first attempt!

My blog is fairly new and though I originally went with Wordpress.com, I switched over to Blogger within a week. Not being able to do code changes like this one on Wordpress was one of the many things that I hated about the WP platform. When I wrote the post, titledThe Top 5 Reasons I Left Wordpress for Blogger, I mentioned you and your blog, and dropped you a couple links.

FrivMo is in my Google Reader and I look forward to your new posts, so I have also added you to my Blogroll of "Blogs I read often" - keep up the good work!

Sammi said...

Thanks heaps!! That was great :)
I've been trying to work out how to get that tag cloud :)

Alessia said...

Thank you so much, Kevin!!!
I just add my voice to the chorus: yours are the easiest to follow and really helpful instructions I've found. I love my new tag cloud, replacing that horrible, very long list of labels!

MORNA said...

Excellent! Clear, correct instructions! Thank you so much. Now for my one question. How can I enlarge the font? The smallest tags are just too small. Thanks! :)

MORNA said...

Sorry - re-commenting just so I can check the box to be notified of follow-up comments. :)

MORNA said...

Third comment is a charm - I figured out how to enlarge font. Thanks for your wonderful site. I think I will create a category for listing good how-to sites - and you will be on the list, for sure! :)

Xphunt3r said...

Very nice and easy to use i just change my label to cloud tag using this on my blog. Thanks man.
http://xphunt3r.blogspot.com

Threeundertwo said...

Perfect. Your instructions are the easiest I've found. Thanks so much!

kyros said...

is there anyway of creating a tag cloud for blogger without having to use labels?

MeduSa said...

awesome. thanks

abby said...

That's awesome, thanks so much!
--
The Hacker Chick Blog

Bri said...

Thank you very much, this is fabulous, it's easy and perfect, exactly as i wanted it to be.

Unfortunately i got the problem when i was trying to put tag cloud to my another blogger blog, everything looks ok, but my tags appear all in the same, small size, i used tags more than once, but they still all are the same size, any advise, please?

thank you :)

leoy said...

Thanks it help me so much..