Getting link rel=”prev/next” links in Magento category pages

Google likes this stuff, so we should utilise tags in the.I could probably put this code in a better place, but for now, I went into my head view file located at app/design/frontend/themename/default/template/page/html/head.phtml

if ($this->getAction()->getFullActionName() == 'catalog_category_view') // Category Page
    $category = Mage::registry('current_category');
    $collection = $category->getProductCollection()
                        ->addAttributeToFilter('status', 1)
                        ->addAttributeToFilter('visibility', array(
                            'in' => array(
    /** @var @var Mage_Page_Block_Html_Pager $tool */
    $tool = $this->getLayout()

    $prev = false;
    $next = false;
    if ($tool->getCollection()->getSelectCountSql())
        if ($tool->getLastPageNum() > 1)
            if (!$tool->isFirstPage())
                $prev = true;
                if ($tool->getCurrentPage() == 2)
                    $url = explode('?', $tool->getPreviousPageUrl());
                    $prev_url = @$url[0];
                    $prev_url = $tool->getPreviousPageUrl();
            if (!$tool->isLastPage()) {
                $next = true;
                $next_url = $tool->getNextPageUrl();
    echo ($prev) ?'<link rel="prev" href="' . $prev_url . '" />' : null;
    echo ($next) ? '<link rel="next" href="' . $next_url . '" />' : null;

If you DON’T have category pages with duplicate content that can be accessed from multiple urls, you can now turn off the canonical tag in the SEO settings. Log into the admin panel, and select System > Configuration > Catalogue  > Search Engine Optimisations. Then you can set Use Canonical Link Meta Tag For Categories to No.

Again, leave it yes if you have duplicate content, ie /crystal-wine-glasses has the same (but less) content than /wine-glasses.

Job done! Google will like that! 😀


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s