Roller: Category list with entry counter
By Kai Seidler on Oct 26, 2009
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.
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! :)