Posted By

ReeceMarsland on 10/21/09


Tagged

php node drupal


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

pjmccormick


Node Paging


 / Published in: PHP
 

simple node paging snippet

  1. <?php
  2. // Previous/Next node paging by title
  3. // See http://2bits.com for details.
  4. // Add this function to the end of the template.php of your theme
  5. function phptemplate_prev_next($current_node = NULL, $op = 'p') {
  6. // Node types to include in paging
  7. $node_types = array('blog');
  8.  
  9. if ($op == 'p') {
  10. $sql_op = '<';
  11. $order = 'DESC';
  12. }
  13. elseif ($op == 'n') {
  14. $sql_op = '>';
  15. $order = 'ASC';
  16. }
  17. else {
  18. return NULL;
  19. }
  20.  
  21. $output = NULL;
  22. foreach($node_types as $type) {
  23. $quoted_types[] = "'" . $type . "'";
  24. }
  25. $sql = "SELECT nid, title FROM {node} n
  26. WHERE nid $sql_op %d
  27. AND type IN (" . implode(',', $quoted_types) . ")
  28. AND status = 1
  29. ORDER BY nid $order
  30. LIMIT 1";
  31. $result = db_query($sql, $current_node->nid, $type);
  32. $data = db_fetch_object($result);
  33. if (!isset($data->nid) || !$data->nid) {
  34. return NULL;
  35. }
  36. return l($data->title, "node/$data->nid", array('html' => TRUE));
  37. }
  38. ?>
  39.  
  40.  
  41. <!-- Node paging start. Add this to your node.tpl.php and/or node-TYPE.tpl.php -->
  42. <?php if (!$teaser) : ?>
  43. <div class="navpn">
  44. <div class="pnlaquo">&laquo;</div>
  45. <div id="pnprev"> <?php print phptemplate_prev_next($node, 'p') ?> </div>
  46. <div id="pnmain"> | <a href="<?php print base_path() ?>">Home</a> | </div>
  47. <div id="pnnext"> <?php print phptemplate_prev_next($node, 'n') ?> </div>
  48. <div class="pnraquo">&raquo;</div>
  49. </div>
  50. <?php endif; ?>
  51. <!-- Node paging end -->
  52.  
  53. /* Add this to your style.css file */
  54. .navpn {
  55. width: 500px;
  56. margin: 0 auto 0 auto;
  57. clear: both;
  58. display: block;
  59. text-align: center;
  60. line-height: 1.5em;
  61. }
  62. #pnprev {
  63. display: block;
  64. float: left;
  65. text-align: right;
  66. width: 200px;
  67. white-space: normal;
  68. word-wrap: break-word;
  69. padding: 0;
  70. }
  71. .navpn #pnmain {
  72. float: left;
  73. text-align: center;
  74. display: inline;
  75. padding: 0 1em 0 1em;
  76. }
  77. #pnnext {
  78. display: block;
  79. float: left;
  80. text-align: left;
  81. width: 200px;
  82. white-space: normal;
  83. word-wrap: break-word;
  84. padding: 0;
  85. }
  86. .pnlaquo {
  87. float: left;
  88. width: 10px;
  89. }
  90. .pnraquo {
  91. float: right;
  92. width: 10px;
  93. }

Report this snippet  

You need to login to post a comment.