Created
September 25, 2017 15:24
-
-
Save simbus82/98715b66576ae800c476594035bdc3f1 to your computer and use it in GitHub Desktop.
REL Prev Next Magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<layout version="0.1.0"> | |
<!-- add rel="prev" and rel="next" for Google SEO --> | |
<catalog_category_default> | |
<reference name="head"> | |
<block type="page/html_pager" name="relprev.next" as="rel_prev_next" template="page/html/rel_prev_next.phtml"/> | |
</reference> | |
</catalog_category_default> | |
<catalog_category_layered> | |
<reference name="head"> | |
<block type="page/html_pager" name="relprev.next" as="rel_prev_next" template="page/html/rel_prev_next.phtml"/> | |
</reference> | |
</catalog_category_layered> | |
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
code originally posted by Inchoo.net | |
http://inchoo.net/magento/how-to-implement-relprev-and-relnext-to-magentos-pagination/ | |
file is app/design/frontend/rwd/default/template/page/html/rel_prev_next.phtml | |
*/ | |
?> | |
<?php | |
$actionName = $this->getAction()->getFullActionName(); | |
if ($actionName == 'catalog_category_view') // Category Page | |
{ | |
$category = Mage::registry('current_category'); | |
$prodCol = $category->getProductCollection()->addAttributeToFilter('status', 1) | |
->addAttributeToFilter('visibility', array('in' => array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH))); | |
$tool = Mage::app()->getLayout()->createBlock('page/html_pager')->setLimit(Mage::app()->getLayout()->createBlock('catalog/product_list_toolbar')->getLimit())->setCollection($prodCol); | |
$linkPrev = false; | |
$linkNext = false; | |
if ($tool->getCollection()->getSelectCountSql()) { | |
if ($tool->getLastPageNum() > 1) { | |
if (!$tool->isFirstPage()) { | |
$linkPrev = true; | |
if ($tool->getCurrentPage() == 2) { | |
$url = explode('?', $tool->getPreviousPageUrl()); | |
$prevUrl = @$url[0]; | |
} | |
else { | |
$prevUrl = $tool->getPreviousPageUrl(); | |
} | |
} | |
if (!$tool->isLastPage()) { | |
$linkNext = true; | |
$nextUrl = $tool->getNextPageUrl(); | |
} | |
} | |
} | |
if ($linkPrev) echo '<link rel="prev" href="' . $prevUrl . '" />'; | |
if ($linkNext) echo '<link rel="next" href="' . $nextUrl . '" />'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment