Blog Bling - Part 2 - Tag Cloud

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".

Comments:

Post a Comment:
Comments are closed for this entry.
About

superpat

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today