You do like asking the harder questions
Totally untested - but give this a go:
get_next_and_prev_cats
Code:
sub {
my ($this_id,$fatherid) = @_;
my $tbl = $DB->table("Category");
$tbl->select_options("ORDER BY Name ASC");
my $sth = $tbl->select( { FatherID => $fatherid } ) || die $GT::SQL::error;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
push @loop, $hit;
}
my ($prev,$next) = ({},{}); # set hashrefs, or else we may get errors!
for (my $i =0; $i <= $#loop; $i++) {
if ($loop[$i]->{ID} == $this_id) {
$prev = $loop[$i-1];
$next = $loop[$i+1];
if ($prev->{ID}) {
$prev->{URL} = $CFG->{build_root_url} . "/" . $DB->table("Category")->as_url( $prev->{Full_Name} ) . "/";
}
if ($next->{ID}) {
$next->{URL} = $CFG->{build_root_url} . "/" . $DB->table("Category")->as_url( $next->{Full_Name} ) . "/";
}
}
}
my $parent_cat = $DB->table('Category')->get( { ID => $fatherid } );
$parent_cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table("Category")->as_url( $parent_cat->{Full_Name} ) . "/";
return {
'next_cat' => $next,
'prev_cat' => $prev,
'parent_cat' => $parent_cat
}
}
Call with:
Code:
<%get_next_and_prev_cats($ID,$FatherID)%>
<%if next_cat.ID%>
<a href="<%next_cat.URL%>"><%next_cat.Name%></a>
<%endif%>
<%if parent_cat.ID%>
<a href="<%parent_cat.URL%>"><%parent_cat.Name%></a>
<%endif%>
<%if prev_cat.ID%>
<a href="<%prev_cat.URL%>"><%prev_cat.Name%></a>
<%endif%>
Totally untested, but should work
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!