Ok, bit more complex than I was expecting ;) I've tested this - and it looks like it should work in all instances
Code:
sub {
my $this_cat_id = $_[0];
my $this_father_id = $_[1];
if (!$this_cat_id || !$this_father_id) { return; }
my $tbl = $DB->table('Category');
$tbl->select_options("ORDER BY Name ASC");
my $sth = $tbl->select( { FatherID => $this_father_id } );
my $prev = {};
my $prev_cat = {};
my $next_cat = {};
my $now_find_next = 0;
while (my $hit = $sth->fetchrow_hashref) {
if ($hit->{ID} == $this_cat_id) {
$prev_cat = $prev;
$now_find_next = 1;
}
if ($now_find_next == 1) {
$now_find_next++;
} elsif ($now_find_next == 2) {
$next_cat = $hit;
last;
}
$prev = $hit;
}
if ($prev_cat->{ID}) {
$prev_cat->{URL} = $CFG->{build_root_url} . "/". $tbl->as_url( $prev_cat->{Full_Name} ) . "/";
}
if ($next_cat->{ID}) {
$next_cat->{URL} = $CFG->{build_root_url} . "/". $tbl->as_url( $next_cat->{Full_Name} ) . "/";
}
return { 'prev_cat' => $prev_cat, 'next_cat' => $next_cat }
}
Code:
<%get_cat_prev_and_next($ID,$FatherID)%>
<%if $prev_cat.ID%>
Prev Category "<a href="<%prev_cat.URL%>"><%prev_cat.Name%></a>"
<%endif%>
<%if $next_cat.ID%>
Next Category "<a href="<%next_cat.URL%>"><%next_cat.Name%></a>"
<%endif%>
NOTE - be sure to add the $FatherID stuff into the global call, or it won't work
ALSO, be sure to change the ORDER BY part, so it uses the same field you want (I set it as ORDER BY Name, so others could also use this global if they wanted :))
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!