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

Top Level Categories in the right column

Quote Reply
Top Level Categories in the right column
Hi,

Is someone know how to always display the list of the top categories ?

Thank you.

____________________
Fabrice
Quote Reply
Re: [fabriceg] Top Level Categories in the right column In reply to
 You can probably make a loop of sorts, but a good old-fashioned global should also work. Something like this, I suspect:
Code:
sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
my @root_cats = $cat_db->select (['Full_Name'], { FatherID => 0 })->fetchall_list;
my $output;
foreach my $root_cat (@root_cats) {
my $url = $cat_db->as_url($root_cat);
$output .= qq~<a href="$CFG->{build_root_url}/$url">$root_cat"</a><br />~;
}
return $output;
}

John
Quote Reply
Re: [gotze] Top Level Categories in the right column In reply to
Well, sure ! thank you.

But, i am a beginer, totaly newbie, you know Wink

So, as stupid as I am, I ask you this Blush: "In a template, how do I use your code ?" (sorry again, I am trying to learn, it is my 2nd day on GLinks Crazy)

____________________
Fabrice
Quote Reply
Re: [fabriceg] Top Level Categories in the right column In reply to
A global has a name, say TopLevelCategories, and is called within a template by using <%TopLevelCategories%> in the template.

To create a global, go to Build > Template Globals. Scroll down and use the New fields. For your new TopLevelCategories global, copy the code above (the "sub"line must be a the very start of the textfield.

That's about it ... Wink

Last edited by:

gotze: Jul 8, 2005, 5:53 AM
Quote Reply
Re: [gotze] Top Level Categories in the right column In reply to
Oh yes ! Thank you very much !

It works Cool Pretty cool;

Merci !

____________________
Fabrice
Quote Reply
Re: [fabriceg] Top Level Categories in the right column In reply to
Hi,

Something like this should work;

Code:
sub {
my ($category,$output);
my $db = $DB->table('Category') || return $GT::SQL::error;
$db->select_options('ORDER BY Full_Name','LIMIT 100') || return $GT::SQL::error;

my $sth = $db->select( ['ID','Full_Name'], { FatherID => 0 } ) || return $GT::SQL::error;

while (my ($id,$full_name) = $sth->fetchrow_array) {
my $safe_full = $full_name;
my @cut = split /\//, $full_name;
$output .= qq|<a href="$CFG->{build_root_url}/| . $db->as_url($safe_full) . qq|">$full_name</a><BR>|. "\n";
}
return \$output;
}

..call it with <%global_name%>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Top Level Categories in the right column In reply to
Thank you very much! Sorry for the late answer, heavy weekend here.

____________________
Fabrice