Blog Bling - Part 2 - Tag Cloud

less than 1 minute read

Back in version 3.1, Apache Roller added support for tags. After Dave Levy blogged about tag clouds, I added one, based on his code:

#set($mytags = $model.weblog.getPopularTags(-1, 100))
#foreach ($tag in $mytags)
#if ($tag.count > 2)
<a class="tag s${tag.intensity}" href="$url.tag($tag.name)"
title="$tag.count">$tag.name</a>
#end
#end

The code is quite simple - we create a set of popular tags, and, for each tag, if there are more than two blog entries with that tag, we create a link. The link’s class is s1, s2…s5 based on the number of entries with that tag (‘tag intensity’). The classes control the font size of the link:

<style type="text/css">
.s1 {
font-size:60%;
}
.s2 {
font-size:80%;
}
.s3 {
font-size:100%;
}
.s4 {
font-size:120%;
}
.s5 {
font-size:140%;
}
</style>

That’s all there is to it. I can link to all entries for a given tag - for example, http://blogs.sun.com/superpat/tags/opensso; there are even RSS feeds per tag - http://blogs.sun.com/superpat/feed/entries/atom?tags=opensso. You can also combine tags to get an intersection - http://blogs.sun.com/superpat/tags/opensso+saml. I’ve completely moved from categories to tags now - “It just works”.

Updated:

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...