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

by Akshay Sangodkar | October 04, 2016 | 0 Comments

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.
 

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?

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

How to Build a Simple HTTP Code Checker in Python with Streamlit

In this RankSense Webinar, we were joined by Charly Wargnier who is a member of the Streamlit Creators Program. Streamlit is a Python open-source library used to make data apps quickly. Charly takes us on his Python journey from starting out in digital marketing with image editing software like Photoshop all the way to working...

READ POST