Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Categories in various numbers of table columns

Quote Reply
Categories in various numbers of table columns
In my directory, I have some categories with very few subcategories and some categories with very many subcategories. I was not satisfied with using a fixed number of columns for displaying these subcategories.

So I made this global that gives you the ablilty to increase the number of columns at certain numbers of subcategories. What I use is:

5 subcats or less: 1 cols
6 - 10 subcats: 2 cols
11 - 20 subcats: 3 cols
more than 20: 4 cols

Here is what is in the template:
Code:
<%if num_cats%>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td valign="top">
<%loop category_loop%>
<%include subcategory.html%>
<%get_break($num_cats,$row_num)%>
<%if break and not last%></td><td valign="top"><%endif%>
<%endloop%>
</td></tr>
</table>
<%endif%>
and here is the global, called get_break()
Code:
sub {
my $total = shift;
my $current = shift;

my @new_col_at = qw/5 10 20/;
my $cols;
for (my $i = 0; $i < @new_col_at; $i++) {
$total <= $new_col_at[$i] and $cols = $i + 1 and last;
}
$cols ||= @new_col_at + 1;

my $breakpoint = int ($total / $cols) + ( ($total % $cols) ? 1 : 0);
return { break => !($current % $breakpoint) ? 1 : 0 };
}
Maybe somebody else finds this useful. You can set your own preferences by modifying the line my @new_col_at = qw/5 10 20/;

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Aug 21, 2002, 4:46 AM
Subject Author Views Date
Thread Categories in various numbers of table columns yogi 3208 Aug 21, 2002, 4:42 AM
Thread Re: [yogi] Categories in various numbers of table columns
KRAEHE 3051 Oct 14, 2002, 1:09 PM
Thread Re: [KRAEHE] Categories in various numbers of table columns
yogi 3018 Oct 16, 2002, 2:42 AM
Post Re: [yogi] Categories in various numbers of table columns
KRAEHE 3009 Oct 16, 2002, 6:28 AM
Thread Re: [yogi] Categories in various numbers of table columns
mick31 2868 Jul 19, 2003, 2:51 PM
Thread Re: [mick31] Categories in various numbers of table columns
afinlr 2773 Oct 17, 2003, 5:01 AM
Post Re: [afinlr] Categories in various numbers of table columns
mick31 2787 Oct 17, 2003, 7:30 AM