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 ...
Attachment | Size |
---|---|
prev-next-node-paging.txt | 2.01 KB |
Comments
Visitor (not verified)
Simple and reusable
Wed, 2009/10/21 - 06:47Just what I was looking for.
Added to snippets :-).
Thanks.
Visitor (not verified)
Great snippet
Thu, 2009/12/10 - 06:29Thanks 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
Visitor (not verified)
Excellent
Mon, 2009/12/28 - 10:15This 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?
st (not verified)
a favour
Thu, 2010/11/04 - 05:47Hi, thank you for sharing this.
Could you please give me some advice/solution what to change in your script to sort blog's entries by date-created instead of node-id?
I would really appreciate your help...
Thank you...
st (not verified)
Hello again, I found it out.
Thu, 2010/11/04 - 14:48Hello again,
I found it out. Anyone interested: i left the solution in this thread http://groups.drupal.org/node/97519#comment-333084
Regards.