Gossamer Forum
Home : Products : Gossamer Links : Discussions :

sub category list

Quote Reply
sub category list
How can I use a global that will return list of categories that are its subcategory and the sub sub category up to the end
Quote Reply
Re: [nir] sub category list In reply to
Hi,

Do you mean you want a global, which would for example:

1) Top Cat
2) Top Cat/Test
3) Top Cat/Test 2
4) Top Cat/Test 2/Sub Cat
5) Top Cat/Test 2/Sub Cat/Another Cat
6) Top Cat/Test 3

...and you wanna get the category "2", and all its sub-categories?

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: [nir] sub category list In reply to
Hi,

Try this global:

get_cats_from_this_cat
Code:
sub {

my $cat = $_[0];
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Category');
$db_obj->select_options ('ORDER BY Full_Name DESC');

my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $sth = $db_obj->select ( $cond) || die $GT::SQL::error;

my @cats;
while (my $hit = $sth->fetchrow_hashref) {

$hit->{URL} = $CFG->{build_root_url} . '/' . $DB->table('Category')->as_url( $hit->{Full_Name} ) . '/' . $CFG->{build_index};
push @cats, $hit;
}

return { cat_loop => \@cats }

}

..then in category.html, put:

Code:
<%get_cats_from_this_cat($category_id)%>
<%if cat_loop.length%>
<%loop cat_loop%>
<%include subcategory.html%>
<%endloop%>
<%endif%>

Untested, but I think this will do what you want Smile

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] sub category list In reply to
Hi Andy, Thanks
I get this error-
Error: Variable 'get_cats_from_this_cat' is not a code reference
I create the gloabal as you sead
Quote Reply
Re: [nir] sub category list In reply to
Mmm,, really? :/ Can't see any reason you would get that error (normally its due to a space at the beginning of the sub { bit or an extra space in sub { - can you send over GLinks admin details, and I'll take a look otherwise.

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] sub category list In reply to
It worksSmile
For some reason the name of the global make the error, after change this is work
Thanks
Quote Reply
Re: [nir] sub category list In reply to
haha cool Wink

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!