How to Indicate Paginated Content in Magento

by Akshay Sangodkar | October 03, 2016 | 0 Comments

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.

Akshay Sangodkar

0

REPLIES

Comments are closed.

Try our SEO automation tool for free!

RankSense automatically creates search snippets using advanced natural language generation. Get your free trial today.

OUR BLOG

Latest news and tactics

What do you do when you’re losing organic traffic and you don’t know why?

Getting Started with NLP and Python for SEO [Webinar]

Custom Python scripts are much more customizable than Excel spreadsheets.  This is good news for SEOs — this can lead to optimization opportunities and low-hanging fruit.  One way you can use Python to uncover these opportunities is by pairing it with natural language processing. This way, you can match how your audience searches with your...

READ POST
Making it easier to implement SEO changes on your website

Changes to the RankSense SEO rules interface

As we continue to improve the RankSense app for Cloudflare, we are always working to make the app more intuitive and easy to use. I'm pleased to share that we have made significant changes to our SEO rules interface in the settings tab of our app. It is now easier to publish multiple rules sheets and to see which changes have not yet been published to production.

READ POST

How to Find Content Gaps at Scale: Atrapalo vs Skyscanner

For the following Ranksense Webinar, we were joined by Antoine Eripret, who works at Liligo as an SEO lead. Liligo.com is a travel search engine which instantly searches all available flight, bus and train prices on an exhaustive number of travel sites such as online travel agencies, major and low-cost airlines and tour-operators. In this...

READ POST

Exciting News!
seoClarity acquires RankSense

X