Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

"next category previous category" global

Quote Reply
"next category previous category" global
hello Smile

i need a hand on a global. here the structure of a site:

Code:
Home >> category01 >> subcat01 >> subsubcat01

what i'd like the global to do is to add a link to the previous and next category (previous and next in the alphabetic order) on the category pages:


Code:
<< previous category next category >>


for examples:

on subcat02 pages:
previous category would link to subcat01
next category would link to subcat03


on subcat01 pages:
previous category would link to subcat12 (the last cat)
next category would link to subcat02


thanks for your time and help Smile

jerome
Quote Reply
Re: [jeromeo] "next category previous category" global In reply to
This is untested so is very probably buggy but should point you in the right direction:

sub {
my $args=shift;
my $db = $DB->table ('Category');
$db->select_options ("ORDER BY $CFG->{build_sort_order_category}") if ($CFG->{build_sort_order_category});
my $sth = $db->select ( {FatherID=>$args->{FatherID}}, [ 'ID' ,'Name','Full_Name'] );
my ($next, $prev, $next_title, $prev_title);
while (my ($id,$title,$fullname) = $sth->fetchrow_array) {
if ($id == $args->{ID}) {
($next,$next_title,$next_full) = $sth->fetchrow_array;
last;
}
else {
$prev = $id;
$prev_title=$title;
$prev_full=$fullname;
}
}
my ($next_url, $prev_url);
if ($next) {
my $temp=$db->as_url($next_full);
$next_url = qq~<a href="/$temp">$next_title >></a>~;
}
if ($prev) {
my $temp = $prev_full;
$prev_url = qq~<a href="/$temp">&lt;&lt; $prev_title</a>~;
}
return {next_url => $next_url, prev_url => $prev_url};
}