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
Quote Reply
Re: [yogi] Categories in various numbers of table columns In reply to
Hi,

I am new on this forum and use LinksSQL 2.1.1 since friday last week.

Something must be changed and your posting is exactly which I looked for.
I make the changed in my templates like your posting and setup the globals
but it does not run.

I see nothing on my side.

Is it possible that i must install the Plugin DirectoryDepth or any other
modifikation needed?

Thanks for your help,




Quote Reply
Re: [KRAEHE] Categories in various numbers of table columns In reply to
Try using

<%GT::Template::dump%>

at the bottom of the category.html template, and see what the values are for "num_cats", and inside "category_loop", what is says for "break".

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Categories in various numbers of table columns In reply to
Hi Ivan,

Thanks for your help, and for the fine global.
I found what i need "category_id"


KRAEHE
Quote Reply
Re: [yogi] Categories in various numbers of table columns In reply to
Hello Yogi,

I use your global : called get_break()

But I have an error :

Catégorie 1 (4)
Error: Variable ' get_break' is not has code reference


Catégorie 2 (6)
Error: Variable ' get_break' is not has code reference


You can help me?

Thank you

Michel
Quote Reply
Re: [mick31] Categories in various numbers of table columns In reply to
I think this is just a misunderstanding - you need to call the global get_break (i.e. without the ()).
Quote Reply
Re: [afinlr] Categories in various numbers of table columns In reply to
Thank you

That is exact.

But, the result is not good

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


But also,

5 subcats or less: 2 cols
6 - 10 subcats: 4 cols
11 - 20 subcats: 6 cols


Too,

I had a display of 13 categories with 1 column (1 line). Frown


The global one seems unstable.

Thank you