If you want to make a good web store, installing Magento is not enough for that. First you should give priority about functional issues of your web store and always keep in mind about Magento’s features. Recently i implement Previous & Next product button on product view page for increase functionality of my web store. To do this i googled and find some good solutions. Here i share about that. You can implement that easily.
I inserted Previous & Next product button after the Product Name in product view page. which is like:

To implement Previous & Next product button you have to edit view.phtml file which is located in:
app/design/frontend/your-instance-name/your-theme/template/catalog/product/view.phtml
If you not found view.phtml there then go:
app/design/frontend/base/default/template/catalog/product/view.phtml
Now open the view.phtml with any code editor. If you want to insert Previous & Next product button after the Product Name as me, then find the following code (line no:49 in version-1.5):
- <div class="product-name">
- <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
- </div>
<div class="product-name"> <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1> </div>
Then insert the following code after the above code:
- <?php // Previous and Next product links in product page
- $_product = $this->getProduct();
- if(!$_product->getCategoryIds())
- return; // Don't show Previous and Next if product is not in any category
- $cat_ids = $_product->getCategoryIds(); // get all categories where the product is located
- $cat = Mage::getModel('catalog/category')->load( $cat_ids[0] ); // load first category, you should enhance this, it works for me
- $order = Mage::getStoreConfig('catalog/frontend/default_sort_by');
- $direction = 'asc'; // asc or desc
- $category_products = $cat->getProductCollection()->addAttributeToSort($order, $direction);
- $category_products->addAttributeToFilter('status',1); // 1 or 2
- $category_products->addAttributeToFilter('visibility',4); // 1.2.3.4
- $cat_prod_ids = $category_products->getAllIds(); // get all products from the category
- $_product_id = $_product->getId();
- $_pos = array_search($_product_id, $cat_prod_ids); // get position of current product
- $_next_pos = $_pos+1;
- $_prev_pos = $_pos-1;
- // get the next product url
- if( isset($cat_prod_ids[$_next_pos]) ) {
- $_next_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_next_pos] );
- } else {
- $_next_prod = Mage::getModel('catalog/product')->load( reset($cat_prod_ids) );
- }
- // get the previous product url
- if( isset($cat_prod_ids[$_prev_pos]) ) {
- $_prev_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_prev_pos] );
- } else {
- $_prev_prod = Mage::getModel('catalog/product')->load( end($cat_prod_ids) );
- }
- ?>
- <div>
- <?php if($_prev_prod != NULL): ?>
- <a href="<?php print $_prev_prod->getUrlPath(); if($search_parameter):?>?search=1<?php endif;?>"><span><?php echo $this->__('PREVIOUS PRODUCT') ?></span></a>
- <?php endif; ?>
- <?php if($_next_prod != NULL): ?>
- <a href="<?php print $_next_prod->getUrlPath(); if($search_parameter):?>?search=1<?php endif;?>"><span><?php echo $this->__('NEXT PRODUCT') ?></span></a>
- <?php endif; ?>
- </div>
<?php // Previous and Next product links in product page
$_product = $this->getProduct();
if(!$_product->getCategoryIds())
return; // Don't show Previous and Next if product is not in any category
$cat_ids = $_product->getCategoryIds(); // get all categories where the product is located
$cat = Mage::getModel('catalog/category')->load( $cat_ids[0] ); // load first category, you should enhance this, it works for me
$order = Mage::getStoreConfig('catalog/frontend/default_sort_by');
$direction = 'asc'; // asc or desc
$category_products = $cat->getProductCollection()->addAttributeToSort($order, $direction);
$category_products->addAttributeToFilter('status',1); // 1 or 2
$category_products->addAttributeToFilter('visibility',4); // 1.2.3.4
$cat_prod_ids = $category_products->getAllIds(); // get all products from the category
$_product_id = $_product->getId();
$_pos = array_search($_product_id, $cat_prod_ids); // get position of current product
$_next_pos = $_pos+1;
$_prev_pos = $_pos-1;
// get the next product url
if( isset($cat_prod_ids[$_next_pos]) ) {
$_next_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_next_pos] );
} else {
$_next_prod = Mage::getModel('catalog/product')->load( reset($cat_prod_ids) );
}
// get the previous product url
if( isset($cat_prod_ids[$_prev_pos]) ) {
$_prev_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_prev_pos] );
} else {
$_prev_prod = Mage::getModel('catalog/product')->load( end($cat_prod_ids) );
}
?>
<div>
<?php if($_prev_prod != NULL): ?>
<a href="<?php print $_prev_prod->getUrlPath(); if($search_parameter):?>?search=1<?php endif;?>"><span><?php echo $this->__('PREVIOUS PRODUCT') ?></span></a>
<?php endif; ?>
<?php if($_next_prod != NULL): ?>
<a href="<?php print $_next_prod->getUrlPath(); if($search_parameter):?>?search=1<?php endif;?>"><span><?php echo $this->__('NEXT PRODUCT') ?></span></a>
<?php endif; ?>
</div>Now save the page & Refresh the product view page of your web store.
Note: You can also use the above code anywhere of the page where you want to show those Buttons.








Nice tutorial about Next-Previous product button, but I’ll try to implement it in a local.xml file, then it’s update proof.