This morning I did some hacking and built my first custom Blogger widget. This is the code for the simple tag cloud you see here on Compender. Feel free to copy and modify the source as you see fit. I tried to comment it best I could so others could fool around with it. It's a mix of JavaScript and Blogger Code, so it is only functional as a Blogger Widget.
Updated 1/2/08 to restrict by a minimum Tag count to reduce clutter for blogs with a zillion tags.
Code:
<b:widget id='TagCloud' locked='false' title='Tags' type='Label'>
<b:includable id='main'>
<b:if cond='data:title'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content' style='text-align: justify;'>
<script type="text/javascript">
/*
Simple Blogger Tag Cloud Widget
by Raymond May Jr.
http://www.compender.com
Released to the Public Domain
*/
//Variables:
var max = 150; //max css size (in percent)
var min = 50; //min css size (...)
var showCount = 1; // show counts? 1 for yes
var minCount = 1; // what is the minimum count for a Tag to be shown? 1 for all.
//Begin code:
var range = max - min;
//Build label Array
var labels = new Array();
<b:loop values='data:labels' var='label'>
labels.push("<data:label.name/>");
</b:loop>
//URLs
var urls = new Array();
<b:loop values='data:labels' var='label'>
urls.push("<data:label.url/>");
</b:loop>
//Counts
var counts = new Array();
<b:loop values='data:labels' var='label'>
counts.push("<data:label.count/>");
</b:loop>
//Number sort funtion (high to low)
function sortNumber(a, b)
{
return b - a;
}
//Make an independant copy of counts for sorting
var sorted = counts.slice();
//Find the largest tag count
var most = sorted.sort(sortNumber)[0];
//Begin HTML output
for (x in labels)
{
if(x != "peek" && x != "forEach" && counts[x] >= minCount)
{
//Calculate textSize
var textSize = min + Math.floor((counts[x]/most) * range);
//Show counts?
if(showCount == 1)
{
var count = "(" + counts[x] + ")";
}else{
var count = "";
}
//Output
document.write("<span style='font-size:" + textSize + "%'><a href='" + urls[x] + "'>" + labels[x] + count + "</a></span> " );
}
}
</script>
</div>
</b:includable>
</b:widget>
Installation:
If you already have a Labels page element installed, skip to step 2.
Step 1: Install the Labels page element by browsing to your template settings:

Click "Add a Page Element" in the column you wish:

Then find the Labels page element and click "Add to Blog":

Step 2: Replace the Labels page element widget code with the custom tag cloud code above.
First navigate to your templates source under your template settings:

Then check off "Expand Widget Templates":

Search for the Label page element you are replacing by searching for widget code. It will look something like this
<b:widget id='Label1' locked='false' title='Tags' type='Label'>but id and title maybe different, so use your browser's search tool and look for type='Label'.
Delete the Label widget code from the start to the end marked by
</b:widget>and replace with the custom Tag Cloud code from above.
100 comments:
It isnt working, although it does shows the element named " Tags" in editor mode by doesnt show on rendered blog page. :s
I just copied the code in another blog and it worked fine. Do you have JavaScript disabled for some reason? Also this only works in the new Blogger (xml layouts version) not the old blogger.
-R
Works like a charm.
Is there a way to trim the number of tags shown, either by frequency rank (i.e. having more than # uses), or by taking the ## more frequent tags?
It cleans up my tag list a lot, but I still have WAAAYYYY too many tags.
I need someone to make a simple widget for me that will work in Yahoo and Google. I simply want a widget to have several URL that when clicked on will open several websites. Would you be interested in creating it for me and if so, what would it cost?
Hi Raymond,
Thanks a lot for sharing.
Just update with last code
and it works has expected!
^^
Regards,
Nuno Luciano
http://gigamaster.blogspot.com/
:)
Thank you... I have been looking to do that for a while. Now all I have to figure out is how to have two side columns instead of one. I guess I should also figure out how to effectively use the labels...
Lots of editing to do...
I'm perplexed. I did exactly as you said, and I have the blogger with xml layouts (hence, "new" Blogger), and all I'm getting is the label Tags in my sidebar, but no tags are showing (even though I have tagged many entries).
Any other tips? Thanks.
This is awesome - you're so smart! I was curious, though... is there a way to remove the parenthetical numbers from each of my labels? That's how yours is on your Compender page - I don't want the numbers to appear after each tag.
I'd appreciate any help you can offer! Thanks so much for what you do.
hi, thanks. it's working in my blog. i just wanted this.
i made slighly change to make the minimum font size bigger.
------------------------------------
//Variables:
var max = 200; //max css size (in percent)
var min = 100; //min css size (...)
var showCount = 1; // show counts? 1 for yes
var minCount = 1; // what is the minimum count for a Tag to be shown? 1 for all.
------------------------------------
Thanks
http://toolnext.blogspot.com/
Thanks for putting this together-
Re: Matthew & Becky-
You can remove the (#) after the labels and specify how often a tag is used before it shows up in the label widget by modifying this code:
var showCount = 1; // show counts? 1 for yes
var minCount = 1; // what is the minimum count for a Tag to be shown? 1 for all.
I changed showCount to = 0 (removes (#) on labels) and changed minCount to be some number over 1, such as 5, and then only my tags with more than 5 uses appeared in the label Widget.
It works great in IE7 as well.
If you copy from above and paste directly to the template code, it will not work as it removes the CR/LF's.
Paste it first into Word or some other word processor and then copy from there and paste the code into the HTML template to get the CR/LF's and the code looks like above.
It works fine. Its great!!
Thank you very much!!!
Thank you so much!
I tried various methods into doing this but yours was the least confusing.
Thanks again!
Raymond, thanks for sharing, it looks great and it was easy. And Rosemary, thanks for the suggestions on the tweaks.
Hi there. I cant seem to get it to work on my new blog. Like needz I just see element names Tags in idebar on my blog. I also tried on Firefox but still no joy. Any ideas. I think if I could get it to work it is a great widget http://bbmarketingbysimon.blogspot.com/
I tryed to install it but your code doesn't work.
My blog is a three columns customized blog with xml custom template.
After cut-and-paste your code, I see only title widget (TAG) and nothing else. So can you help me? thank you very much
Well. It's work now.
There's a bug that your code dosn't display any label if there's a label with special character like "
Worked well for me, thanks !!
Works super well! This is exactly what I needed! Thank you
great! it works very very well!
now i will pimp it!
=)
Thank you thank you thank you!!! :D
First I could only get the word "Tags" to show up in the blog, but then I read the advise of the others here and copied the code into Word BEFORE I continued and copied it from Word into the HTML-page on Blogger.
I know absolutely nothing of HTML but still I could get this to work! THANK YOU! This page was a big help! :D
thanks it work for me too
Nice widget. Exactly what I was looking for. It worked flawless in my blog. Thanks!
thanks, it's working...
you very genius bro :)
Nice work!
I've been looking for a simple implementation of the tagcloud...and all I've had is headaches & heartaches...
Until your code & implementation tutorials. Took me less than a minute, and it worked like a charm, thanks a million...;-)
but one thing...in my template I get the number of instances of the word. Is there a way to remove that? thanks
I had to copy and paste into Word as well but it's working now.
Thanks!
Fantastic. Worked like a charm!
Great tag cloud, thanks for creating it.
See how it looks at: http://egovau.blogspot.com/
Again it only worked for me when I pasted the code into Word and then into Blogger.
I made a slight change to the code you may want to consider as well.
I changed the class (to tagcloud-content) and added a unique style (as I didn't want the tags underlined by default).
This would also work to change a tag cloud's colour, font or other attributes and follows the standard blogger scripting approach for custom styles in page elements.
NOTE: I replaced the < and > brackets below with [ and ] so the system would allow me to post the code.
[div class='tagcloud-content' style='text-align: justify;]
[!-- Apply custom style. --]
[style type='text/css'
.tagcloud-content a:link {
color:[data:linkColor/];
text-decoration: none;
}
[/style]
At last, a Tag cloud which looks good in Blogger. Excellent work Raymond. Thank you. However, at first I hade the same problem as Needz and Sofie above – I could only see the headline Tags on my blog, but noting more. I then follow Sofies advice and first pasted the code into Word. That worked swell. Sofie - thank you for your suggestion.
Sorry, it seems to be "Broker Carlos Bravo" above who came up with the idea of using Word. Many Thanks.
looks absolutely great! thanks a bunch
Thank you so much! I couldn't get it to work at first, then I tried reading the instructions. Here it is in action:
http://www.jankyvision.com
Consuming.........
Participating......
Producing/creating..........
Sharing..........
You are tops to create & share...thanks
Thank you! it works! yay!
worked for me as did changing font size and removing the (1) after tags. Thanks!
I'm wondering how to make every tag stick together,no blank between them?
Thanks for your help!
Awesome work. Really like it. Thanks!
http://futureofreason.blogspot.com/
that's awesome!! Thanks
Pure GENIUS! Thank you! ^__^
REALLY helpful, thanks so much!
Is it possible to tweak (or override) the proportional font effect? I'd like a less dramatic contrast, and the single-item tags seem too small on my blog.
http://cmcarchives.blogspot.com
Thanks again for a great solution!
Thanks a lot! I love the cloud :)
Thank you! I also had to copy it into Word first, but then it worked perfectly!
Hey, thanks. I'm HTML illiterate, but I did decipher that I need to keep the *bwidget* in my code, above the labels bwidget. I thought, at first that you meant I should delete my label code that *begins* and ends with *bwidget*. But yours only has the ending *bwidget*, so I kept that one above my tag label code.
I'm the proud parent of a new tag cloud! Thanks for the infusion!
--fcm
http://mrsmomkit.blogspot.com
worked like a charm, thanks a lot!
will
howtheotherhalfworks.blogspot.com
Thanks a lot... Works great on my site http://botsnhacks.blogspot.com
Just make minor adjustments.(100-200 font size and 0 value to showcount)
It isnt working to me..
i've read something about the fact that with tags with " " it doesn't work.
is right?
i've a tag with " " and maybe this is the problem?
can i modify a row of the widget code for solve it or have to change all the posts with the tag " " ?
thanks!
Thank you very much.
Working like a charm.
I have found another Code for Blogger TagCloud at http://technoexperts.blogspot.com/2008/08/new-blogger-tag-cloud-widget.html.
This worked great with no problems! Thanks so much for providing this to us bloggers. We appreciate you!
Neat code. Thank you!
Thank you!
Thank you, I really really appreciate the clear instructions with visuals!
This works great! It makes me want to tag everything just to see it change!!!
Works great! Why don't you submit this to blogger so it will become one of the basic widgets. It's very good.
Awesome Widget mate, it works like a charm,
cheers!
Muzzerino
it's working! thx for the simple label cloud :D
Please refer to http://websitewealth.blogspot.com/2008/08/new-blogger-tag-cloud-widget.html as Previous blog has been removed.
I also changed my font size
var max = 125; //max css size (in percent)
var min = 75; //min css size (...)
As of now it works great... hope there is no bug or something later :)
thank's
Works fine for me... see my blogs...
http://zpiderboi.blogspot.com
Thanks! That was much easier than I thought it would be...
Thanks for sharing!
Very simple, easy and ellegant. Worked just fine!
To know more about Tag Clouds check out :
http://rochakchauhan.com/blog/2008/09/15/how-to-implement-tag-clouds-in-php/
Works great. Thank you!
Great tool, thanks.
If anyone is getting the "Tags" header without any tags beneath, it seems to be caused by cutting and pasting the code directly into a text editor, which removes line breaks and spacing.
As a previous commenter pointed out, the fix is to cut and paste into Word, then into your code. That fixed the problem for me.
Thank you for the code. just the widget that i have been looking for.
Thanks for posting this. I teach organizations how to leverage new media for strategic communications and I'm adding this widget to my live demos line-up.
Thank you! I added it to Vibrant Healthy U.com and it looks great! I appreciate you sharing this!
Thanx
iam use this widget
http://isonlyanime.blogspot.com
Finally, a tag Cloud that works!!! Thanks for writing something that is simple but works great!
http://mastersofthelinuxuniverse.blogspot.com/
That is so cool Mr. It worked first time for me. Also, it fitted itself into my sidebar (which is too narrow for other tag clouds I tried) and it is justified text which I just love and it blended itself to the colour of my blog !
Thankyou very much from a happy Romanian gal xx
http://alookatromaniaandromanians.blogspot.com
If I add it to my other blog will it adjust in the same way...
http://carlyluvsunited.blogspot.com
Thanks so much. Once I pasted it into word it worked like a charm!
I have been desperate to find a simple, clean and efficient tag cloud. It worked perfectly for me on the very first try with no errors, problems, annoyances, hassles (minor or major), etc. Thanks!
Thank you thank you thank you! Like many others who've already commented this is exactly what I was hoping for and it really did work like a charm. Thanks to the adaptations to adjust size that were also suggested and the 'how-to' for removing the numbers. So very cool. And I truly know nothing about html. Woooo hoooo!
And yes, I too suggest you submit it to Blogger to become an option in the growing list of widgets they offer through their editing pop-up. It's excellent!
this works great, but once published, does not seem to be editable (workaround: keep your template locally, which you should do anyway of course). Nice job!
my bad...of course it's editable... I missed the "expand widget templates" checkbox on the Edit HTML page. Great stuff Raymond.
great work, many many thx!!!
i'm using it here: http://inseecp.blogspot.com/
keep the good work...
deborah
www.lomodeedee.com
Greate job, it worked on my blog:
http://wszqdq.blogspot.com/
Thanks a lot for this widget. It works really fine :)
¡Gracias!
This is super great!!! Thanks for posting your Tag Cloud 'how-to'. I'm a new blogger and was looking in the Blogger list for a Tag Cloud, no luck. Searched Google and there your page was. It was easy to install, easy to personalize because of so many useful comments of others, and in fact, easy to re-install after I made some major template changes! Super Super Super!!!
Thank you very much, it works great!
I just made a small adaptation, so it would look better on my blog. I've added a "padding-right" on the DIV CSS in order to prevent the labels touching widget right edge.
http://winterviajando.blogspot.com
thanks, just install your widget and i love it. :)
big thank you. Had to copy/paste in IE because Firefox came up with an error message but i guess that's Firefox's problem.
Thank you so much been trying to do this for a while and never got around to it :)
Thank you very much! I'm using it now.
thanks man it's work for utf-8 charset, thanks
I'm your tag-cloud fan! But there are certain groups of labels/tags that I wish to hide from the cloud, but I have no clue how to do this.
Repetitive posts like photos and images will drive up the tag-counts and they would make the links for the text posts very small. I'd still need the labels on the photo posts and would handle them in a diff text widget menu (or even diff tag cloud).
Any advice on how to tweak the code?
Thanks in advance,
> mousehuntguide.blogspot.com
Thank you very much for this one! i'm using it now on my blog.
Thanks!
Great widget! Fast loading, clean code, detailed comments and good how-to-install blog entry.
Using it now at streams4freedom, works and looks great!
Agree. Work like a charm. Great job.
I was looking for a tag cloud for blogger and found this one. It works great and I also used the other users' help to increase the font size. Just wanted to thank you.
From Lisbon, Portugal.
Madalena
It works! Thanks a lot
thanks so much!!
thanks it helps me :p
HELP!!!
I keep getting this error message when putting in the new code:
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:widget" must be terminated by the matching end-tag ""
What is going on?
Any suggestions?
Post a Comment