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
Oct 28, 2008, 8:57 AM
Veteran / Moderator (18436 posts)
Oct 28, 2008, 8:57 AM
Post #2 of 7
Views: 4630
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!
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!
Oct 28, 2008, 9:07 AM
Veteran / Moderator (18436 posts)
Oct 28, 2008, 9:07 AM
Post #3 of 7
Views: 4642
Hi,
Try this global:
get_cats_from_this_cat
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:
<%if cat_loop.length%>
<%loop cat_loop%>
<%include subcategory.html%>
<%endloop%>
<%endif%>
Untested, but I think this will do what you want
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!
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

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!
Oct 28, 2008, 9:59 AM
Veteran / Moderator (18436 posts)
Oct 28, 2008, 9:59 AM
Post #5 of 7
Views: 4640
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!
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!
Oct 30, 2008, 5:43 AM
Veteran / Moderator (18436 posts)
Oct 30, 2008, 5:43 AM
Post #7 of 7
Views: 4621
haha cool
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!

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!