How can I display a list off all subcategory of specific category?
Jul 24, 2008, 4:50 AM
Veteran / Moderator (18436 posts)
Jul 24, 2008, 4:50 AM
Post #2 of 7
Views: 4059
Is this just gonna be something hard-coded onto a page? If so - something like this should work:
Category :
Test
Test/1
Test/2
Test/3
Testing 2
Testing 2/Bla
Testing 2/Bla 2
Homepage
..and show (for example)
Testing 2
Testing 2/Bla
Testing 2/Bla 2
..is that what your after?
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!
Category :
Test
Test/1
Test/2
Test/3
Testing 2
Testing 2/Bla
Testing 2/Bla 2
Homepage
..and show (for example)
Testing 2
Testing 2/Bla
Testing 2/Bla 2
..is that what your after?
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!
Jul 24, 2008, 5:54 AM
Veteran / Moderator (18436 posts)
Jul 24, 2008, 5:54 AM
Post #4 of 7
Views: 4052
Hi,
Still not 100% sure what your asking for - but try this:
get_categorys_by_id
my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $tbl = $DB->table('Category');
$tbl->select_options ('ORDER Full_Name');
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $sth = $tbl->select ( $cond ) || die $GT::SQL::error;
my @cats;
while (my $hit = $sth->fetchrow_hashref) {
$hit->{URL} = $CFG->{build_root_url} . $tbl->as_url($hit->{Full_Name}) . '/' . $CFG->{build_index};
push @cats, $hit;
}
return { cat_loop => \@cats }
}
<ul>
<%loop cat_loop%>
<il><a href="<%Name%>"><%Name%></a></li>
<%endloop%>
</ul>
(change "1234" to the category ID you want to get)
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!
Still not 100% sure what your asking for - but try this:
get_categorys_by_id
Code:
sub { my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $tbl = $DB->table('Category');
$tbl->select_options ('ORDER Full_Name');
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $sth = $tbl->select ( $cond ) || die $GT::SQL::error;
my @cats;
while (my $hit = $sth->fetchrow_hashref) {
$hit->{URL} = $CFG->{build_root_url} . $tbl->as_url($hit->{Full_Name}) . '/' . $CFG->{build_index};
push @cats, $hit;
}
return { cat_loop => \@cats }
}
Code:
<%get_categorys_by_id(1234)%> <ul>
<%loop cat_loop%>
<il><a href="<%Name%>"><%Name%></a></li>
<%endloop%>
</ul>
(change "1234" to the category ID you want to get)
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!
Thanks,
There was a small bug I change it and now it work
One thing – Not it display the category and the subcategory, his there a way that it will not display the category. I mean if I use <%get_categorys_by_id(2)%>
That it will display the subcategory of "2" but not the "2" itself
sub { my $cat = shift; my $all_ids = $DB->table('Category')->children($cat); push @$all_ids, $cat; my $tbl = $DB->table('Category'); $tbl->select_options ('ORDER BY Full_Name'); my $cond = GT::SQL::Condition->new('ID', 'IN', $all_ids); my $sth = $tbl->select ( $cond ) || die $GT::SQL::error; my @cats; while (my $hit = $sth->fetchrow_hashref) { $hit->{URL} = $CFG->{build_root_url} . $tbl->as_url($hit->{Full_Name}) . '/' . $CFG->{build_index}; push @cats, $hit; } return { cat_loop => \@cats } }
There was a small bug I change it and now it work
One thing – Not it display the category and the subcategory, his there a way that it will not display the category. I mean if I use <%get_categorys_by_id(2)%>
That it will display the subcategory of "2" but not the "2" itself
sub { my $cat = shift; my $all_ids = $DB->table('Category')->children($cat); push @$all_ids, $cat; my $tbl = $DB->table('Category'); $tbl->select_options ('ORDER BY Full_Name'); my $cond = GT::SQL::Condition->new('ID', 'IN', $all_ids); my $sth = $tbl->select ( $cond ) || die $GT::SQL::error; my @cats; while (my $hit = $sth->fetchrow_hashref) { $hit->{URL} = $CFG->{build_root_url} . $tbl->as_url($hit->{Full_Name}) . '/' . $CFG->{build_index}; push @cats, $hit; } return { cat_loop => \@cats } }
Jul 24, 2008, 6:41 AM
Veteran / Moderator (18436 posts)
Jul 24, 2008, 6:41 AM
Post #6 of 7
Views: 4042
Cool - just delete:
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!
Code:
push @$all_ids, $cat;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!