You are here

README.txt in Previous/Next API 7.2

Same filename and directory in other branches
  1. 8.2 README.txt
  2. 6 README.txt
  3. 7 README.txt
Copyright 2009 http://2bits.com

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.

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 is defined in the settings too. The default is 200, but you may
want to lower that for a site on shared hosts. Once the indexing is complete for all the site's
nodes, cron will do do anything. You can always reindex the site using the "Re-Index" button
on the settings page.

API
===

The module provides only one API call. If you do not call that function from another module
or your theme, this module will do nothing.

<?php
$n_nid = prev_next_nid($nid, $op);
?>

Examples for using it are:

<?php
// 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 for nodes that are of content
type 'image' or 'video', add the following function in your template.php file,
or a custom module:

<?php
function pn_node($node, $mode = 'n') {
  if (!function_exists('prev_next_nid')) {
    return NULL;
  }

  switch($mode) {
    case 'p':
      $n_nid = prev_next_nid($node->nid, 'prev');
      $link_text = 'previous';
      break;

    case 'n':
      $n_nid = prev_next_nid($node->nid, 'next');
      $link_text = 'next';
      break;

    default:
      return NULL;
  }

  if ($n_nid) {
    $n_node = node_load($n_nid);

    $options = array(
      'attributes' => array('class' => 'thumbnail'),
      'html'  => TRUE,
    );
    switch($n_node->type) {
      // For image nodes only
      case 'image':
        // This is an image node, get the thumbnail
        $html = l(image_display($n_node, 'thumbnail'), "node/$n_nid", $options);
        $html .= l($link_text, "node/$n_nid", array('html' => TRUE));
        return $html;

      // For video nodes only
      case 'video':
        foreach ($n_node->files as $fid => $file) {
          $html  = '<img src="' . base_path() . $file->filepath;
          $html .= '" alt="' . $n_node->title;
          $html .= '" title="' . $n_node->title;
          $html .= '" class="image image-thumbnail" />';
          $img_html = l($html, "node/$n_nid", $options);
          $text_html = l($link_text, "node/$n_nid", array('html' => TRUE));
          return $img_html . $text_html;
        }
      default:
        // Add other node types here if you want.
    }
  }
}
?>

Then in your node-image.tpl.php and node-video.tpl.php you call this function as follows:

<code>
  <ul id="node-navigation">
    <li class="next"><?php print pn_node($node, 'n'); ?></li>
    <li class="prev"><?php print pn_node($node, 'p'); ?></li>
  </ul>
</code>

Alternately, you can also add the calls to pn_node() in the phptemplate_preprocess_node()
function of your template.php file for the content types you are interested in.

Bugs/Features/Patches:
----------------------
If you want to report bugs, feature requests, or submit a patch, please do so
at the project page on the Drupal web site.
http://drupal.org/project/prev_next

Author
------
Khalid Baheyeldin (http://baheyeldin.com/khalid and http://2bits.com)

If you use this module, find it useful, and want to send the author
a thank you note, then use the Feedback/Contact page at the URL above.

The author can also be contacted for paid customizations of this
and other modules.

File

README.txt
View source
  1. Copyright 2009 http://2bits.com
  2. An API for browsing next/previous nodes without overloading your database server.
  3. Description
  4. ===========
  5. This module allows you to know the previous or next nodes for any given node. This
  6. is very useful for providing navigational links to the user without the expensive
  7. queries required to dynamically deduce such information on the fly.
  8. The use case is two fold:
  9. Usability/Navigation
  10. --------------------
  11. For example, on a site with a gallery of images, you want to show a next/previous link
  12. with a thumbnail under each image. Your site's visitor click on the link to show new
  13. content or browse it.
  14. Scalability
  15. -----------
  16. Although the previous and next nodes can be deduced with some SQL work, the queries to
  17. do so are very heavy on the database, and can bring a site to its knees. This module
  18. solves this problem by storing the previous/next node in a table so lookups are fast.
  19. Once the module is installed, it will build this index backwards via cron until all
  20. nodes have been indexed.
  21. Configuration
  22. =============
  23. The module can be restricted to certain content types to be included in the previous/next
  24. indexing. For example, you want the site's visitors to browse through video and image nodes
  25. only, but not blogs and regular pages.
  26. The number of nodes to index is defined in the settings too. The default is 200, but you may
  27. want to lower that for a site on shared hosts. Once the indexing is complete for all the site's
  28. nodes, cron will do do anything. You can always reindex the site using the "Re-Index" button
  29. on the settings page.
  30. API
  31. ===
  32. The module provides only one API call. If you do not call that function from another module
  33. or your theme, this module will do nothing.
  34. $n_nid = prev_next_nid($nid, $op);
  35. ?>
  36. Examples for using it are:
  37. // Get the previous node id
  38. $prev_nid = prev_next_nid($nid, 'prev');
  39. // Get the previous node id
  40. $next_nid = prev_next_nid($nid, 'next');
  41. ?>
  42. Example
  43. -------
  44. To implement the functionality for this module for nodes that are of content
  45. type 'image' or 'video', add the following function in your template.php file,
  46. or a custom module:
  47. function pn_node($node, $mode = 'n') {
  48. if (!function_exists('prev_next_nid')) {
  49. return NULL;
  50. }
  51. switch($mode) {
  52. case 'p':
  53. $n_nid = prev_next_nid($node->nid, 'prev');
  54. $link_text = 'previous';
  55. break;
  56. case 'n':
  57. $n_nid = prev_next_nid($node->nid, 'next');
  58. $link_text = 'next';
  59. break;
  60. default:
  61. return NULL;
  62. }
  63. if ($n_nid) {
  64. $n_node = node_load($n_nid);
  65. $options = array(
  66. 'attributes' => array('class' => 'thumbnail'),
  67. 'html' => TRUE,
  68. );
  69. switch($n_node->type) {
  70. // For image nodes only
  71. case 'image':
  72. // This is an image node, get the thumbnail
  73. $html = l(image_display($n_node, 'thumbnail'), "node/$n_nid", $options);
  74. $html .= l($link_text, "node/$n_nid", array('html' => TRUE));
  75. return $html;
  76. // For video nodes only
  77. case 'video':
  78. foreach ($n_node->files as $fid => $file) {
  79. $html = '' . $n_node->title;
</li><li>          $html .= '';
  80. $img_html = l($html, "node/$n_nid", $options);
  81. $text_html = l($link_text, "node/$n_nid", array('html' => TRUE));
  82. return $img_html . $text_html;
  83. }
  84. default:
  85. // Add other node types here if you want.
  86. }
  87. }
  88. }
  89. ?>
  90. Then in your node-image.tpl.php and node-video.tpl.php you call this function as follows:
  91. Alternately, you can also add the calls to pn_node() in the phptemplate_preprocess_node()
  92. function of your template.php file for the content types you are interested in.
  93. Bugs/Features/Patches:
  94. ----------------------
  95. If you want to report bugs, feature requests, or submit a patch, please do so
  96. at the project page on the Drupal web site.
  97. http://drupal.org/project/prev_next
  98. Author
  99. ------
  100. Khalid Baheyeldin (http://baheyeldin.com/khalid and http://2bits.com)
  101. If you use this module, find it useful, and want to send the author
  102. a thank you note, then use the Feedback/Contact page at the URL above.
  103. The author can also be contacted for paid customizations of this
  104. and other modules.