Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Category list global including build_category_columns

Quote Reply
Category list global including build_category_columns
I currently have my root level cats displaying in 5 columns on my home page and want to be able to include this table on a number of other pages.

I know I can display a list of cats using a category list global like this:

sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Name');
my $sth = $cat_db->select ( { FatherID => 0}, ['Full_Name','Name'] );
my $output="";
while (my ($root_cat,$full_name) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($root_cat);
$output .= qq~<li><a href="$CFG->{build_root_url}/$url/"><b>$full_name</b></a></li>~;
}
return $output;
}


But I am having trouble getting this to output a table with "build_category_columns" columns.

I have looked at site_html_print_cat to try and get some ideas, but not having much success. I know I could hard code a table and call it in, but my number of categories is expected to change quite a bit and its on the cards that I will be changing the number of columns now and again also, so I would rather this be all automated.

If anyone could help with this it would be appreciated Smile

cheers
Mark
Quote Reply
Re: [marker] Category list global including build_category_columns In reply to
anyone? Unsure
Quote Reply
Re: [marker] Category list global including build_category_columns In reply to
Did anyone ever figure this out?

CCUnet
my Christian web
Quote Reply
Re: [ccunet] Category list global including build_category_columns In reply to
I ended up coming up with this, which seems to work ok Smile

Code:
sub {
my $width = int (100 / $CFG->{build_category_columns});
my $table_head = $CFG->{build_category_table} || '';
my $output=qq~<table $table_head><tr><td width="$width%" align="left" valign="top">\n~;
my $cat_db = $DB->table('Category');
$cat_db->select_options('ORDER BY Name');
my $sth = $cat_db->select ( {'FatherID' => 0}, ['Full_Name','Name'] );
my $total = $cat_db->count ( {'FatherID' => 0}, ['Full_Name','Name'] );
my $breakpoint = int (($total) / $CFG->{build_category_columns}) + ( (($total) % $CFG->{build_category_columns}) ? 1 : 0);
my $i=0;
while (my ($cat,$full_name) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($cat);
($i > 0) and !($i % $breakpoint) and ($output .= qq~</td>\n<td width="$width%" align="left" valign="top">\n~);
$i++;
$output .= qq~<li><a href="$CFG->{build_root_url}/$url/">$full_name</a></li>~;
}
$output .= qq~</td></tr></table>\n~;
return $output;
}



Mark
Quote Reply
Re: [marker] Category list global including build_category_columns In reply to
Thanks Marker,
The dsiplay works great but unfortunately the links seem to get broken due to mod rewrite I'm using.

CCUnet
my Christian web
Quote Reply
Re: [ccunet] Category list global including build_category_columns In reply to
This global is returning this error
Code:

(GT::SQL::Table (835): Wrong argument passed to this subroutine. Arguments to count()
must either be a hash, or one or more hash refs and/or GT::SQL::Condition objects at (eval 21) line 8.

for this line
Code:

my $total = $cat_db->count ( {'FatherID' => 0}, ['Full_Name','Name'] );

in LSQL 2.2.1
Can anyone give a clue as to why and or how to fix it?
Thanks
CCUnet
my Christian web
Quote Reply
Re: [ccunet] Category list global including build_category_columns In reply to
I think it should just be

my $total = $cat_db->count ( {'FatherID' => 0});
Quote Reply
Re: [afinlr] Category list global including build_category_columns In reply to
Thanks, I'll give that a try

CCUnet
my Christian web