<div id="product-navigation">
<?php
/**
* Determine the previous/next link and link to current category
*/
if ($this->helper('catalog/data')->getCategory()) {
$_ccat = $this->helper('catalog/data')->getCategory();
} else {
$_ccats = $this->helper('catalog/data')->getProduct()->getCategoryIds();
$_ccat = Mage::getModel('catalog/category')->load($_ccats[0]);
}
$ppos = $_ccat->getProductsPosition();
$current_pid = $this->helper('catalog/data')->getProduct()->getId();
// build array from products positions
foreach ($ppos as $pid => $pos) {
$plist[] = $pid;
}
// get link for prev product
$previd =
isset($plist[$curpos+1])?
$plist[$curpos+1] :
$current_pid;
$product = Mage::getModel('catalog/product')->load($previd);
$prevpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$prevpos += 1;
$nextid =
isset($plist[$prevpos])?
$plist[$prevpos] :
$current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$prev_url = $product->getProductUrl();
// get link for next product
$nextid =
isset($plist[$curpos-1])?
$plist[$curpos-1] :
$current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
$nextpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$nextpos -= 1;
$nextid =
isset($plist[$nextpos])?
$plist[$nextpos] :
$current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$next_url = $product->getProductUrl();
// get link for current category
$more_url = $_ccat->getUrl();
$current_cid = $_ccat->getId();
?>
<p><a href=
"<?= $more_url; ?>" class=
"product_category"><?php
echo $_ccat->
getName() ?></a></p>
<p><a href="<?= $next_url; ?>" class="product_prev">Nazaj</a>
<a href="<?= $prev_url; ?>" class="product_next">Naprej</a></p>
</div>