0

I have created a custom module, for pagination added this block:

protected function _prepareLayout()
{
    parent::_prepareLayout();

    $pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
    $pager->setAvailableLimit(array(3=>3,6=>6,9=>9,'all'=>'all'));
    $pager->setCollection($this->getCollection());
    $this->setChild('pager', $pager);
    $this->getCollection()->load();
    return $this;
}

public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}

Added following in template file:

<?php echo $this->getPagerHtml(); ?>    

My pagination url's work as: http://test.com/test-landing.html?p=2

But instead of "p" I want to use "page" like this way http://test.com/test-landing.html?page=2

How can I do that ?

Thanks

0

For this you have to override Magento\Theme\Block\Html\Pager like below:

create etc/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Theme\Block\Html\Pager">
        <plugin name="name-your-plugin" type="Vendor\Module\Plugin\PagerPlugin" sortOrder="5" />
    </type>
</config>

create PagerPlugin.php under Vendor\Module\Plugin

<?php

namespace Vendor\Module\Plugin;

class PagerPlugin
{    

    public function afterGetPageVarName(\Magento\Theme\Block\Html\Pager $subject, $result)
    {

        return "page";
    }

}
?>
  • I am using magento 1 not for magento 2 – Rahul Singh Aug 10 '18 at 7:07
  • then override this file Mage_Page_Block_Html_Pager and change protected $_pageVarName = 'p'; to protected $_pageVarName = 'page'; – mighty_hk Aug 10 '18 at 8:13
  • But I want it for the custom module only – Rahul Singh Aug 10 '18 at 8:52
  • override Mage_Page_Block_Html_Page and override below method: public function getPageVarName() { if(condition_for_your_module) {return "page";}else{ return $this->_pageVarName; } } – mighty_hk Aug 10 '18 at 9:39
  • Happy coding. :) If things work out, don't forget to upvote as it may help others also. – mighty_hk Aug 10 '18 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.