Junkfood

Food and Junk.

All | Food | Junk | Work

20050124 Monday January 24, 2005

Roller: Re-ordering the Category Bar

The following macro allows you to re-order Categories shown by the showWeblogCategoryChooser macro. Specifically, it alphabetically sorts Categories by their Descriptions. I don't think that the Description field is used elsewhere, so it is probably safe to use it as a sorting key.

#macro( showWeblogSubcategoryChooser2 $parentCategory $divider )
    #set( $rawUrl = "$ctxPath/page/$userName/$page.link" )

    <div class="rWeblogCategoryChooser">
    #set( $weblogUrl = $rawUrl )
    #set( $chosenCat = "" )
    #if( $req.getParameter( $WEBLOGCATEGORYNAME_KEY ) )
        #set( $chosenCat = $req.getParameter( $WEBLOGCATEGORYNAME_KEY ) )
        <span class="rUnchosenCategory"><a href="$weblogUrl">
        $text.get( "macro.weblog.allcategories" )</a></span>
    #else
        <span class="rChosenCategory">$text.get( "macro.weblog.allcategories" )</span>
    #end

    #if ( $req.getParameter($PAGEID_KEY)  )
        #set( $pageParam = "&$PAGEID_KEY=$req.getParameter($PAGEID_KEY)" )
    #end
    #set( $rawcats = $pageModel.getWeblogCategories($parentCategory) )
    ## // Sort categories by description, using a bubble sort.
    ## // The "All" category is not sorted; it's always first.
    #set( $cats = [] )
    #foreach( $rawcat in $rawcats )
       #set ($curcat = $rawcat)
       #set ($catcounter = 0)
       #foreach ($cat in $cats)
            #if ($curcat.description.compareTo($cat.description) < 0)
                #set ($curcat = $cats.set($catcounter, $curcat))
            #end
            #set ($catcounter = $catcounter + 1)
        #end
        #if ($cats.add($curcat))
        #end
    #end
    #foreach( $cat in $cats )
        ## $pageHelper.strutsUrlHelper() wasn't working, so do it manually
        #set( $catParam = "?$WEBLOGCATEGORYNAME_KEY=$utilities.encode($cat.path)" )
        #set( $weblogUrl = "$rawUrl$catParam$!pageParam" )
        $divider
        #if( $chosenCat == $cat.path )
            <span class="rChosenCategory">$cat.Name</span>
        #else
            <span class="rUnchosenCategory"><a href="$weblogUrl">$cat.Name</a></span>
        #end
    #end
    </div>
#end

The macro does not change category order anywhere else. Specifically, it does not change it in the Search drop-down menu or in the New Weblog Entry category drop-down menu (and therefore the default category for new entries is also unchanged). It also doesn't change the position of the "All" category (which is always in the first position).

I'm not sure how Roller orders categories by default. It's either reverse alphabetical order by name or reverse of the order that the categories were added.

(2005-01-24 13:00:00.0) Permalink |

Comments:

Post a Comment:

Comments are closed for this entry.

Calendar

« November 2009
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

Recent Entries

Search

Navigation



XML