I've received a few inquiries into how I created the
tag cloud for this site, and figure it would be easiest to explain how it's done here. This site is powered by Movable Type so the instructions are specific to this platform. However, they could likely be ported to other blogging platforms that use categories or tags without too much trouble.
The beauty of this solution is it doesn't involve any true programming. Personally, I have an easier time adding 2+2+2 than 2x3, so I take the easy route whenever possible. Or, I'm just lazy. This solution is based on a
more elegant solution using PHP found here. If you're not familiar with PHP, or can't run PHP on your server, this is the way to go. I use CSS to do with RichardZ does with PHP.
Creating a tag cloud instructions: 1. Create a new page for your site for the tag cloud.
Click here for instructions on how to do this. I called our tag cloud page
tagcloud.html but it doesn't matter what it's called (and doesn't have to have a .php extension).
2. Clear the body of the new page.
3. Paste the following code into the body of your tag cloud page (where you'd like the tag cloud to appear:
<!-- Start Tag Cloud -->
<div id="cloud">
<MTCategories>
<a href="<$MTCategoryArchiveLink$>"
class="tag<$MTCategoryCount$>"><$MTCategoryLabel
lower_case="1"$></a> </MTCategories>
</div>
<!-- End Tag Cloud -->
This publishes your site's categories in a row that wraps whenever it reaches the end of the line. Each category is hyperlinked to the appropriate archive page.
The
div id="cloud" tag allows you to format the tag cloud using CSS.
class="tag<$MTCategoryCount$> adds a CSS class to each tag that's unique to the number of posts in each category. When published, this converts to
class="tag4" for a category with four posts.
Okay, that covers the work on the page. Now for a few additions to your site's style sheet. If you save and republish the page, it should build your tag cloud with no formatting.
4. Go to Templates and open styles-site.css.
5. Add the following code to the bottom of the style sheet:
/* Start Tag Cloud CSS */
#cloud {padding:1px; line-height:30px;text-align:center;}
#cloud a {text-decoration:none;padding:0px;}
a.tag1{
font-size:12px;
}
a.tag2, a.tag3 {
font-size:13px;
font-weight:200;
}
a.tag4 ,a.tag5, a.tag6 {
font-size:16px;
font-weight:300;
}
a.tag7, .tag8, a.tag9 {
font-size:20px;
font-weight:300;
}
a.tag10, a.tag11, a.tag12 {
font-size:24px;
font-weight:300;
}
a.tag13, a.tag14, a.tag15 {
font-size:28px;
font-weight:400;
}
a.tag16, a.tag17, a.tag18 {
font-size:30px;
font-weight:400;
}
a.tag19, a.tag20, a.tag21 {
font-size:32px;
font-weight:500;
}
a.tag22, a.tag23, a.tag24 {
font-size:34px;
font-weight:500;
}
a.tag25, a.tag26, a.tag27 {
font-size:36px;
font-weight:900;
}
a.tag28, a.tag29, a.tag30 {
font-size:38px;
font-weight:900;
}
/* End Tag Cloud CSS */
6. Save and rebuild your style sheet.
7. Refresh your tag cloud. It should now be formatted.
The CSS tags listed above gradually increase the font site, (and some include an increase in font weight as well) as the number associated with posts in a category increases. The font sizes and post numbers associated with different sizes can be adjusted here, changing the look of your tag cloud. It may take some experimentation to find a format that is suitable for the number of categories used in your site, and your post volumes to various categories.
8. Link to your tag cloud from your site's templates.
9. Remove the categories section from you site's templates.
10. Done.
Find this useful? If you implement this on your site, consider adding a link to TechnologyEvangelist.com.
Questions? Add them to the comments below.
Did you port this to other blogging platforms? Let us know in the comments.
1. Posted by: Roald Marth on March 8, 2006 7:23 PM:
Happy Birthday Ed, I hope you enjoy yourself tonight, thanks for the great story before you went to your party!! Peace Out....Ro