Roller: Category list with entry counter

Sun Microsystem's blogs.sun.com employee blogging site (affectionately named BSC) uses Apache Roller to manage the site and house all the blogs. Roller is an open source Java blog software that for example also drives the US Government's blog.usa.gov and the IBM Developer Works blogs. But there is one feature I really missed: An entry counter in my sidebar's category list. It's a standard feature in the Wordpress world, but in Roller I didn't found any option enabling such a counter.

categoriecounter.png

But as they say, "If the mountain won't come to Mohammed, then Mohammed will go to the mountain": If the feature will not come to me, then I will need to take care by myself.

And here is my mountain:

#set($rootCategory = $model.weblog.getWeblogCategory("nil"))

#set($cats = $rootCategory.getWeblogCategories())
#foreach($cat in $cats)
  #set($entriesList = $model.weblog.getRecentWeblogEntries($cat.name, 500))
  #set($count = $entriesList.size())
  #if($model.weblogCategory && $model.weblogCategory.path == $cat.path)
    <li class="selected"><a href="$url.category($cat.path)">$cat.name ($count)</a></li>
  #else
    <li><a href="$url.category($cat.path)">$cat.name ($count)</a></li>
  #end
#end

It's quite easy and straight forward: Get a list of all categories, for each category get all the blog entries (in this case limited to 500, because I don't know how this scales), count the entries, and finally generate some HTML.

If everything would be that easy! :)

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Kai 'Oswald' Seidler writes about his life as co-founder of Apache Friends, creator of XAMPP, and technology evangelist for web tier products at Sun Microsystems.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
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