This project is not covered by Drupal’s security advisory policy.

An API for browsing next/previous nodes without overloading your database server.

Description

This module allows you to know the previous or next nodes for any given node. This is very useful for providing navigational links to the user without the expensive queries required to dynamically deduce such information on the fly.

The use case is two fold:

Usability/Navigation

For example, on a site with a gallery of images, you want to show a next/previous link with a thumbnail under each image. Your site's visitor click on the link to show new content or browse it.

Scalability

Although the previous and next nodes can be deduced with some SQL work, the queries to do so are very heavy on the database, and can bring a site to its knees. This module solves this problem by storing the previous/next node in a table so lookups are fast. Once the module is installed, it will build this index backwards via cron until all nodes have been indexed. See the "More Info" section below for a detailed post on the positive scalability impacts of implementing this module.

Configuration

The module can be restricted to certain content types to be included in the previous/next indexing. For example, you want the site's visitors to browse through video and image nodes only, but not blogs and regular pages.

The number of nodes to index on each cron run is defined in the settings too. The default is 200, but you may want to lower that for a site on shared hosts. You can always reindex the site using the "Re-Index" button on the settings page.

Creating new nodes will auto-index and generate the Prev and Next links. For already-existing nodes at install time, you will need to bulk save them. Go to your content page and under bulk actions select 'Save Content" on all nodes that you want to be indexed.

API

The module provides only one API call. If you do not call that function, this module will do nothing.

$n_nid = prev_next_nid($nid, $op);

Examples for using it are:

// Get the previous node id
$prev_nid = prev_next_nid($nid, 'prev');

// Get the previous node id
$next_nid = prev_next_nid($nid, 'next');

Example

To implement the functionality for this module, please see the example in the README.txt file provided with this module.

Future development

At present, the module does not provide for indexing content by criteria other than the node type.
The 7.x-2.x version of this module allows indexing of nodes by taxonomy terms as well.

Other use cases may call for additional criteria, for example, a term id, so content is browsed by taxonomy terms. This will require database schema changes and reindexing of the site again.

More info

For more info on the performance impact of this module on large sites, please read Previous/Next API: a high performance API module for previous/next node.

Comparison of Other Solutions

Depending on your site and needs, you may want to compare other methods of generating previous and next links.

Sponsors

Development sponsored by: WebMediaBrands for Ads of the World

Author

Khalid Baheyeldin of 2bits.com.

The author can also be contacted for paid customizations of this module as well as Drupal consulting, installation, development, and customizations.

Project information

Releases