Question speaks for it self. I found 2 blog posts about it. Should I create my own helper class like Here or do it right in view.phtml like here. Which would be best approach and isn't there a better one?

4 Answers 4


Should I create my own helper class or do it right in view.phtml?

The answer is both.

You need to create a helper and then call that class form within view.phtml as described in the Inchoo article.

Both the links you've supplied are using the same code, but the one from Inchoo is the original post with the other one being a copy+paste job with some tiny modifications. Use the Inchoo code, it is the best way to implement this functionality on a standard site.

Take note of what the article says about layered navigation - this code will only work with standard categories that have 'Is Anchor' set to 'No'.


There is also another Previous/Next Products extension created by Branko Ajzele. You can find it on github: https://github.com/ajzele/Inchoo_Prevnext (take a look at the original Blog post)

The basic idea is to create an observer, which grabs the currently loaded product collection from product list block. So this one is actually working with layered navigation.


The inchoo code didn't work for me. This works though:

function getNextProductUrl($category, $currentProduct) {

    $productPositions = $category->getProductsPosition();
    $sortedCatProductIds = array_keys($productPositions);

    $currentProductCategoryIndex = @array_search($currentProduct->getId(), $sortedCatProductIds);

    $nextProductIds = array_slice($sortedCatProductIds, $currentProductCategoryIndex + 1, count($sortedCatProductIds)); //+1 for next product, -1 for previous product

    foreach ($nextProductIds as $productId) {
        $product = Mage::getModel('catalog/product')->load($productId);

        if ($product && $product->getId() && $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility()) {
            return $product->getProductUrl();

    return false;
  • Great @Willster. We were having some problems too. Did you update the Inchoo code? Or make your own solution? Would love to see complete
    – snh_nl
    Jul 30, 2015 at 7:40
  • @snh_nl I came up with my own solution based on various sources. And I'm not sure what you mean by 'complete'. The above function IS complete. You need to pass it a category and the current product. Not sure what more you'd want!? And if you find an answer useful on stack exchange, it's customary to up vote it.
    – Willster
    Jul 30, 2015 at 10:00
  • Checkout the Inchoo code on github. We just added a pull request to improve. Anyway thanks.
    – snh_nl
    Jul 30, 2015 at 10:44

There is an extension by aheadWorks I worked with in the past. It is not cheap, but does its job.


  • 3
    I'm not sure I'd recommend adding the bloat of an AW module (with its questionable licensing system) for the sake of a back/forwards link. It could be done with 2 lines of inline code. Mar 7, 2013 at 10:13
  • can you tell me more about the licencing? Mar 7, 2013 at 10:31
  • On a comment here no - its not for discussion. Go into chat :) Mar 7, 2013 at 10:33
  • 3
    Don't get me wrong. I'm not putting AW down - but solving functionality through bolting on extension after extension is just asking for trouble; especially for a task as simple as this Mar 8, 2013 at 14:54
  • 1
    The tendency with Magento is to add a new extension every time you come across something that isn't standard. The AW extension is good for store owners who can't code, want a solution that works out of the box and gives them a place to customise every single variable through config fields. As @sonassi said this is a very basic task and seeing as this is primarily a coding forum I think the best answer would be one that helps developers achieve this functionality for themselves. Mar 12, 2013 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.