Next and Prev products links on node page

Public

Displays 'next' and 'prev' lnks for products.
Should be inserted in node-product.tpl.php

</> CopyGet raw version
php
  1. $q = db_query('SELECT nid, title from {node} WHERE type = "product";');
  2. $anid = array(); $atitle = array();
  3. while($row = db_fetch_array($q)){
  4. $anid[] = $row['nid'];
  5. $atitle[] = $row['title'];
  6. }
  7. $idx = -1;
  8. for($i=0; $i<count($anid); $i++){if ($anid[$i] == $node->nid){$idx = $i;}}
  9. if ($idx > 0){$prev = '<span class="previous_product">Предыдущие <a href="/'.drupal_get_path_alias('node/'.$anid[$idx-1]).'">'.$atitle[$idx-1].'</a></span>';}
  10. if ($idx < count($anid)-1){$next = '<span class="next_product"><a href="/'.drupal_get_path_alias('node/'.$anid[$idx+1]).'">'.$atitle[$idx+1].'</a> следующие</span>';}
  11. if ($next){echo $next;}
  12. if ($prev){echo $prev;}

Comments