How to Optimize Pagination Using the View-all Page In Magento

Introduction

This step-by-step tutorial follows the How to Indicate Paginated Content in Magento tutorial and is designed to help developers and users optimize pagination using the view-all page in a Magento Ecommerce Platform category collection of products. Users usually prefer using a view-all page instead of browsing through a collection of pages. With the view-all page activated in Magento, Google recommends that the view-all page URL should be used as a canonical URL for all the individual pages. This becomes easier for Google because the view-all page is a super-set and rel=”prev” and rel=”next” indicate individual pages.

The tutorial involves editing PHP files, therefore some knowledge of PHP and HTML is needed to execute the steps. Also, please remember to make a backup of files that are to be edited.

Duration To Complete: 20 mins

Prerequisites

Magento Open Source Ecommerce Platform v1.9.1.0

Step 1

First, complete the tutorial How to Indicate Paginated Content in Magento.

Activate the view-all page in Magento. In Magento Admin Panel, go to System –> Configuration –> Catalog –> Catalog –> Frontend. Set Allow All Products per Page to Yes. Below is a screenshot.

Here is how the view-all page looks in our example Sample Store category.

Step 2

In Step 5 of the tutorial How to Indicate Paginated Content in Magento, we added custom code in head.phtml to indicate pagination tags and canonical tags to Google. We optimize the code further to indicate the view-all page URL as the canonical URL for category collections.

In the Magento base directory (in our setup it is /var/www), find head.phtml in the path app/design/frontend/rwd/default/template/page/html/ and open it in your favorite editor. Search for the following code snippet.

echo ‘<link rel=”canonical” href=”‘ . Mage::helper(‘core/url’)->getCurrentUrl(). ‘” />’;

Replace it with the following.

$pieces = explode(“?”, Mage::helper(‘core/url’)->getCurrentUrl());

echo ‘<link rel=”canonical” href=”‘ . $pieces[0] . ‘?limit=all” />’;

The entire custom code should look like this.

<?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’,

 

Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)));

$tool =

$this->getLayout()->createBlock(‘page/html_pager’)->setLimit($this->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()

After implementing Step 2 in the sample Magento store, the resulting HTML of page 2 of a category is as follows.

<link rel=”prev” href=“http://magento.samplestore.biz/accessories-9.html” />

<link rel=”next” href=“http://magento.samplestore.biz/accessories-9.html?p=3/>

<link rel=”canonical” href=”http://magento.samplestore.biz/accessories-

9.html?limit=all” />

Check using developer tools in Google Chrome browser by typing Ctrl + Shift + i. Below is a snapshot.

Conclusion

With these simple steps, we have activated the view-all page for products and indicated to Google to use the view-all page as the canonical URL for paginated collections of products in a category.

 

How to Indicate Paginated Content in Magento

Introduction

This step-by-step tutorial is designed to help developers and users indicate paginated content in the Magento Ecommerce Platform collection of products. Google search engine will be able to treat multiple pages of products as a single entity and understand that the pages are a logical sequence. Hence, the value of inbound links will not be diluted among the pages.

The tutorial involves editing PHP files, therefore some knowledge of PHP and HTML is needed to execute the steps. Also, please remember to make a backup of files which are to be edited.

We also use the “15-Minute SEO Audit” with RankSense free Chrome Browser Extension to detect common SEO issues and help optimize.

Duration To Complete: 30 mins

Prerequisites

Magento Open Source Ecommerce Platform v1.9.1.0

Step 1

In Magento base directory (in our setup it is /var/www), we modify the code in the template file app/design/frontend/base/default/template/page/html/head.phtml which generates the head part of an HTML page in Magento. It’s best not to modify files in the base theme, so we copy head.phtml to the rwd theme while preserving the folder structure. The new template file is stored as app/design/frontend/rwd/default/template/page/html/head.phtml. If you already have head.phtml in your theme, then use that template file instead.

Step 2

Open app/design/frontend/rwd/default/template/page/html/head.phtml in your favorite viewer.

$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 =

$this->getLayout()->createBlock(‘page/html_pager’)->setLimit($this->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();

}

This will show rel=”prev” and rel=”next” link tags to indicate paginated content of categories of products. If it’s the first page then only the rel=”next” link tag is indicated. If it’s the last page then only the rel=”prev” link tag is indicated. For all other pages, both link tags are indicated. The number of pages must be greater than one in order to indicate the link tags.

Here is the resulting HTML for page 2 of a category in our sample Magento store.

<link rel=”prev” href=“http://magento.samplestore.biz/accessories-9.html” />

<link rel=”next” href=“http://magento.samplestore.biz/accessories-9.html?p=3/>

Check using developer tools in Google Chrome browser by pressing Ctrl + Shift + i. Below is a snapshot.

 

Step 3

Install “15-Minute SEO Audit” with RankSense free Chrome Browser Extension. This browser extension looks for common SEO issues in the current web page. It adds automatic SEO issue detection to the Chrome Developer Tools. We use it in this step to detect issues with the pagination tags.

Press Ctrl + Shft + i in Google Chrome browser to access developer tools. Click on the RankSense tab to use the extension as shown in the snapshot below. Analyzing pagination tags for page 2 of a category in our sample Magento store, we find that there is one pagination warning which says “Canonical tag is not self-referential“. This is a common mistake and means that the canonical tag cannot be the first page in the set. We provide a fix in the next step.

Step 4

The canonical link meta tag for categories in Magento is automatically generated depending on an SEO setting in Admin Panel. In Magento Admin Panel, go to the System –> Configuration –> Catalog –> Search Engine Optimizations section. Below is a snapshot that shows Use Canonical Link Meta Tag For Categories set to Yes.

We fix the pagination warning detected by RankSense Chrome browser extension in Step 2. The fix is that the canonical link meta tag should be self-referential. Currently it points to the first page only.

Set Use Canonical Link Meta Tag For Categories to No. This will disable auto-generation of canonical link meta tags for categories. Below is a snapshot.

Step 5

Open app/design/frontend/rwd/default/template/page/html/head.phtml in your favorite editor. Add the following snippet …

echo ‘<link rel=”canonical” href=”‘ . Mage::helper(‘core/url’)->getCurrentUrl()

. ‘” />’;

… to the code mentioned in Step 2 as shown below.

<?php

$actionName = $this->getAction()->getFullActionName();

if ($actionName == ‘catalog_category_view’) // Category Page

{

$category = Mage::registry(‘current_category’);

array(‘in’ => array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG,

 

 

Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)));

$tool =

$this->getLayout()->createBlock(‘page/html_pager’)->setLimit($this->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();

}

}

This generates self-referential canonical link meta tags for category pages in Magento, and also generates pagination tags.

After implementing Step 4 and Step 5 in the sample Magento store, the resulting HTML of Page 2 of a category is as follows.

<link rel=”prev” href=“http://magento.samplestore.biz/accessories-9.html” />

<link rel=”next” href=“http://magento.samplestore.biz/accessories-9.html?p=3/>

<link rel=”canonical” href=”http://magento.samplestore.biz/accessories-9.html?p=2″ />

Analyze using RankSense Browser Extension as follows. It shows that the pagination issue detected in Step 3 is fixed.

Check using Google Chrome developer tools. Below is a snapshot.

Conclusion

With these simple steps we have indicated to Google not to dilute the value of inbound links among pages and treat all pages belonging to a category as a single entity. Using RankSense Browser Extension we have ensured that pagination is optimized by generating self-referential canonical link meta tags for category pages in Magento.

How to Optimize Use Of Canonical URLs In Magento

Introduction

This step-by-step tutorial is designed to help developers and users optimize use of canonical link meta tags in Magento Ecommerce Platform content pages, category pages, and product pages. Search engines such as Google, Bing, Yandex, and Yahoo! impose duplicate content penalties on websites, which may affect their ranking in search results. Canonical URLs help search engines crawl duplicate content only once by indicating the URL that contains most of the duplicate content.

The tutorial involves editing PHP files, therefore some knowledge of PHP and HTML is needed to execute the steps. Also, please remember to make a backup of files that are to be edited.

We also use the “15-Minute SEO Audit” with RankSense free Chrome Browser Extension to detect common SEO issues and help optimize.

Duration To Complete: 20 mins

Prerequisites

Magento Open Source Ecommerce Platform v1.9.1.0

Step 1

In Magento Admin Panel, go to System –> Configuration –> Catalog –> Search Engine Optimizations. Set Use Categories Path for Product URLs and Use Canonical Link Meta Tag For Products to Yes. Here is a snapshot.

With Use Canonical Link Meta Tag For Products set to Yes, Magento automatically generates canonical link meta tags for products pages. With Use Categories Path for Product URLs set to Yes, each product web page can be accessed using two URLs, one with the categories path, for example http://magento.samplestore.biz/mobiles/boogle-texus-6.html and one without, for example http://magento.samplestore.biz/boogle-texus-6.html. Though these are duplicate URLs, the canonical link meta tag eliminates the duplicity.

Press Ctrl + Shft + i in Google Chrome browser to access developer tools. Click on the RankSense tab to use the extension to check canonicalization of a product page as shown in the snapshot below.

Step 2

The canonical link meta tag for categories in Magento is automatically generated depending on an SEO setting in Admin Panel. In Magento Admin Panel, go to the System –> Configuration –> Catalog –> Search Engine Optimizations section. Below is a snapshot that shows Use Canonical Link Meta Tag For Categories set to Yes.

Press Ctrl + Shft + i in Google Chrome browser to access developer tools. Click on the RankSense tab to use the extension as shown in the snapshot below. Analyzing pagination tags for page 2 of a category in our sample Magento store, we find that there is one pagination warning which says Canonical tag is not self-referential. This is a common mistake and means that the canonical tag cannot be the first page in the set.

Set Use Canonical Link Meta Tag For Categories to No. This will disable auto-generation of canonical link meta tags for categories. Below is a snapshot.

In the Magento base directory (in our setup it is /var/www), we modify the code in the template file app/design/frontend/base/default/template/page/html/head.phtml which generates the head part of an HTML page in Magento. It’s best not to modify files in the base theme, so we copy head.phtml to the rwd theme while preserving the folder structure.

The new template file is stored as app/design/frontend/rwd/default/template/page/html/head.phtml. If you already have head.phtml in your theme, then use that template file instead.

Open app/design/frontend/rwd/default/template/page/html/head.phtml in your favorite editor. Add the following code snippet at the end of the file.

[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 = $this->getLayout()->createBlock(‘page/html_pager’)->setLimit($this->getLayout()-

>createBlock

$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 ”; if ($linkNext) echo ”; echo ‘getCurrentUrl() . ‘” />’;

}
[/php]

This generates self-referential canonical link meta tags for category pages in Magento, and also generates pagination tags.

After implementing Step 2 in the sample Magento store, the resulting HTML of Page 2 of a category is as follows.

<link rel=“prev” href=“http://magento.samplestore.biz/accessories-9.html” />

<link rel=“next” href=“http://magento.samplestore.biz/accessories-9.html?p=3/>

<link rel=“canonical” href=http://magento.samplestore.biz/accessories-9.html?p=2″ />

Analyze using RankSense Browser Extension again as follows. It shows that the issue is fixed.

Check using Google Chrome developer tools. Below is a snapshot.

Conclusion

With these simple steps we have reduced duplication of content using canonical link meta tags for categories and products in Magento. Using RankSense Browser Extension we have ensured that canonicalization is optimized by generating self-referential canonical link meta tags for category pages in Magento.