Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Re: [iplay] Next/Previous Category

Quote Reply
Re: [iplay] Next/Previous Category In reply to
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 Wink

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!

Last edited by:

Andy: Jun 6, 2011, 2:05 AM
Subject Author Views Date
Thread; hot thread Next/Previous Category iplay 8179 Jun 5, 2011, 12:29 PM
Thread; hot thread Re: [iplay] Next/Previous Category
Andy 8011 Jun 6, 2011, 12:40 AM
Thread; hot thread Re: [Andy] Next/Previous Category
iplay 8022 Jun 6, 2011, 12:47 AM
Thread; hot thread Re: [iplay] Next/Previous Category
Andy 8049 Jun 6, 2011, 12:59 AM
Thread; hot thread Re: [Andy] Next/Previous Category
iplay 8044 Jun 6, 2011, 1:09 AM
Thread; hot thread Re: [iplay] Next/Previous Category
Andy 8009 Jun 6, 2011, 1:35 AM
Thread; hot thread Re: [Andy] Next/Previous Category
iplay 8019 Jun 6, 2011, 1:40 AM
Post; hot thread Re: [iplay] Next/Previous Category
Andy 8026 Jun 6, 2011, 1:50 AM
Thread; hot thread Re: [iplay] Next/Previous Category
Andy 8013 Jun 6, 2011, 2:03 AM
Thread; hot thread Re: [Andy] Next/Previous Category
iplay 7995 Jun 6, 2011, 2:30 AM
Thread; hot thread Re: [iplay] Next/Previous Category
Andy 8034 Jun 6, 2011, 2:31 AM
Post; hot thread Re: [Andy] Next/Previous Category
iplay 7989 Jun 6, 2011, 3:20 AM