Simple previous / next navigation by node title

Published Mon, 2009/10/05 - 14:26

We have posted before on how to display previous/next thumbnails for image nodes. We also have a module that is basically a Previous/Next API for high volume / high performance sites.

But sometimes you need a simpler solution for regular nodes, just using the node title and a link to it. This article explains how to achieve that for Drupal 6 in one simple function and a few changes to one .tpl.php file.

First, we start off with the code that does the heavy lifting.

In your theme's template.php add the first function from the attached file. By default it provides paging for blog posts only. You can change that to another type of node (or multiple types).

The code is fast, since it uses the nid as an index. So if you use this on large sites, it would not slow them down.

Then in your node.tpl.php, or node-TYPE.tpl.php, add the second snippet in the attached file. This provides calls to the next/previous node with hyperlinked titles.

For the styling, add the CSS from last snippet in the attached file.

The final result will look like this on a garland theme:

Hope you enjoy this ...

AttachmentSize
prev-next-node-paging.txt2.01 KB

Excellent

This is an excellent little snippet.

One draw back is that your nodes must be in sequential order, such as node/21, node/22, node/23.
If node/22 is taken up by a different content type, then next button will not appear on node/21.

Is there a work around for this?

Great snippet

Thanks for sharing this uesful snippet
Too bad this can't be done with view and arguments
Arguments in view needs other comparison operators than equal

keep going

Simple and reusable

Just what I was looking for.

Added to snippets :-).

Thanks.