1. <div id="product-navigation">
  2. <?php
  3. /**
  4. * Determine the previous/next link and link to current category
  5. */
  6. if ($this->helper('catalog/data')->getCategory()) {
  7. $_ccat = $this->helper('catalog/data')->getCategory();
  8. } else {
  9. $_ccats = $this->helper('catalog/data')->getProduct()->getCategoryIds();
  10. $_ccat = Mage::getModel('catalog/category')->load($_ccats[0]);
  11. }
  12. $ppos = $_ccat->getProductsPosition();
  13. $current_pid = $this->helper('catalog/data')->getProduct()->getId();
  14. // build array from products positions
  15. $plist = array();
  16. foreach ($ppos as $pid => $pos) {
  17. $plist[] = $pid;
  18. }
  19. $curpos = array_search($current_pid, $plist);
  20. // get link for prev product
  21. $previd = isset($plist[$curpos+1])? $plist[$curpos+1] : $current_pid;
  22. $product = Mage::getModel('catalog/product')->load($previd);
  23. $prevpos = $curpos;
  24. while (!$product->isVisibleInCatalog()) {
  25. $prevpos += 1;
  26. $nextid = isset($plist[$prevpos])? $plist[$prevpos] : $current_pid;
  27. $product = Mage::getModel('catalog/product')->load($nextid);
  28. }
  29. $prev_url = $product->getProductUrl();
  30. // get link for next product
  31. $nextid = isset($plist[$curpos-1])? $plist[$curpos-1] : $current_pid;
  32. $product = Mage::getModel('catalog/product')->load($nextid);
  33. $nextpos = $curpos;
  34. while (!$product->isVisibleInCatalog()) {
  35. $nextpos -= 1;
  36. $nextid = isset($plist[$nextpos])? $plist[$nextpos] : $current_pid;
  37. $product = Mage::getModel('catalog/product')->load($nextid);
  38. }
  39. $next_url = $product->getProductUrl();
  40. // get link for current category
  41. $more_url = $_ccat->getUrl();
  42.  
  43. $current_cid = $_ccat->getId();
  44. ?>
  45.  
  46. <p><a href="<?= $more_url; ?>" class="product_category"><?php echo $_ccat->getName() ?></a></p>
  47.  
  48. <p><a href="<?= $next_url; ?>" class="product_prev">Nazaj</a>
  49. <a href="<?= $prev_url; ?>" class="product_next">Naprej</a></p>
  50. </div>