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:
<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()
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
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%>
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 };
}
Ivan
-----
Iyengar Yoga Resources / GT Plugins