Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Next/Previous Category

Quote Reply
Next/Previous Category
Is there any way to have automatic links in a category template to next and previous category, similar to the next and previous Detailed Page links, eg <%prev_url%>?

Thanks,
--Jo
Quote Reply
Re: [iplay] Next/Previous Category In reply to
Mmm probably, but not sure how easy it would be.

Are you thinking of just having it alphabetically, in order based on the category you are in? For example, if in:

Foo/Bar/Test

..and the structure looks like:

Test Category
Foo/Bar/123
Foo/Bar/ABC
Foo/Bar/Test
Foo/Bar/Umm
Whatever

..then it would show the "Prev" as "ABC", and "Next" as "Umm"

However, in "Umm", it would show nothing for "Next" (as there are no sub-categories after it) .... and then same goes for the 123 category not showing the "Prev" link either.

Lemme know, and I'll see if I can come up with something Wink

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!
Quote Reply
Re: [Andy] Next/Previous Category In reply to
Yes, that's exactly it, except that the Categories are not sorted alphabetically.

They are sorted by a field called AbsWkNo entered in build_category_sort.

You can see the Categories listed under "Weeks of the Year" at:
http://www.englishclub.com/this-week-in-history/Archive/

Thanks,
--Jo
Quote Reply
Re: [iplay] Next/Previous Category In reply to
Totally untested, but give this a go:

get_cat_prev_and_next
Code:
sub {
my $cat_id = $_[0];

my $tbl = $DB->table('Category');
$tbl->select_options("ORDER BY AbsWkNo DESC LIMIT 1");
my $prev_cat = $tbl->select( { ID => $cat_id } )->fetchrow_hashref || {};
$prev_cat->{URL} = $CFG->{build_root_url} . "/". $tbl->as_url( $prev_cat->{Full_Name} ) . "/";

$tbl->select_options("ORDER BY AbsWkNo ASC LIMIT 1");
my $next_cat = $tbl->select( { ID => $cat_id } )->fetchrow_hashref || {};
$next_cat->{URL} = $CFG->{build_root_url} . "/". $tbl->as_url( $next_cat->{Full_Name} ) . "/";

return {
'next_cat' => $next_cat,
'prev_cat' => $prev_cat
}
}

Then in category.html, call with:

Code:
<%get_cat_prev_and_next($ID)%>
<%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%>

Hope that helps Angelic

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!
Quote Reply
Re: [Andy] Next/Previous Category In reply to
Thanks Andy. I presume that was to go in globals, which I did and called as you suggested.

The resulting links are to the current page as you see at:
http://www.englishclub.com/...verest_Is_Conquered_

Thanks,
--Jo

Last edited by:

iplay: Jun 6, 2011, 1:12 AM
Quote Reply
Re: [iplay] Next/Previous Category In reply to
Ah whoops, serves me right coding before my coffee ;)

Try changing the 2 instances of:

LIMIT 1

..to:

LIMIT 1,1

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!
Quote Reply
Re: [Andy] Next/Previous Category In reply to
Done, but now the Previous/Next links disappear altogether:
http://www.englishclub.com/...irst_Man_Into_Space/

Go have that coffee Wink

Thanks,
--Jo

Last edited by:

iplay: Jun 6, 2011, 1:41 AM
Quote Reply
Re: [iplay] Next/Previous Category In reply to
Mmm, I see the problem. Bit of a major flaw in the logic Tongue

Just trying to think how I could change it...mmmm

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!
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
Quote Reply
Re: [Andy] Next/Previous Category In reply to
Brilliant! That works Laugh

Thanks Andy,
--Jo

Last edited by:

iplay: Jun 6, 2011, 2:31 AM
Quote Reply
Re: [iplay] Next/Previous Category In reply to
Np - I may add this to my ULTRAGlobals plugin at some point, as I'm sure some other people may also find it useful :)

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!
Quote Reply
Re: [Andy] Next/Previous Category In reply to
Andy wrote:
I may add this to my ULTRAGlobals plugin at some point, as I'm sure some other people may also find it useful
I'm sure it would be Smile

Thanks,
--Jo