% /* Don't change variables without comments, unless you know what you are doing. They are mostly used for counting stuff. */ $col = 1 $linkcounter=1 $nbr_per_col=4 /* Number of categories per column. It is calculated automaticly below. */ $nbr_per_col_min=5 /* The minimum amount of categories displayed in a column. */ IF $mobilemenu THEN $nbr_col=1 ELSE $nbr_col=4 /* The total number of columns */ ENDIF $add_extra_link=0 $force_break=0 $odd_nbr=0 $levels=1 /* Topmenues are level 0, their children are level 1 and so on. Set levels=1 to get two levels of categories for example. */ $Data.state='ACTIVE' /* Make sure we only get active categories */ QUERY CATEGORY_TREE(category_id=$page_id, levels=$levels) DO IF $CATEGORY_TREE.Numrows THEN IF $nbr_col THEN $nbr_per_col=$Numrows/$nbr_col /*Code to avoid extra columns*/ IF $Numrows%$nbr_col THEN $nbr_per_col=$nbr_per_col+1 $odd_nbr=1 ENDIF $nbr_per_col=$[I]nbr_per_col IF $nbr_per_col<$nbr_per_col_min THEN $nbr_per_col=$nbr_per_col_min ENDIF /*Handle Corner case (avoid to few columns)*/ IF ($Numrows%$nbr_per_col==0) AND $odd_nbr THEN $add_extra_link=1 $nbr_per_col=$nbr_per_col-1 ENDIF IF $nbr_per_col<1 THEN $nbr_per_col=1 ENDIF ENDIF%>