3

I need to show products pagination in the file template\catalog\product\list.phtml. How can I do it? Probably I need to edit catalog.xml but what to change I don't know.

4
  • template\catalog\product\list.phtml is a category page and by default pagination is present in this page. Dec 6, 2013 at 9:13
  • @AnshuMishra, well $this->getpagerhtml() is accesible in \template\catalog\product\list\toolbar.phtml, but in the list.phtml it shows nothing.
    – CoalaArmy
    Dec 6, 2013 at 10:36
  • Are you not getting only pagination or whole pagination block (containing product listing styles, pagination and sorting dropdown) ? Dec 6, 2013 at 10:45
  • @AnshuMishra, I get the it the toolbar.phtml, but I need the in list.phtml. If I write the pager functions in list.phtml then they show nothing.
    – CoalaArmy
    Dec 6, 2013 at 10:53

4 Answers 4

4

$this->getPagerHtml() in catalog\product\list\toolbar.phtml means you are trying to call getPagerHtml() method of class Mage_Catalog_Block_Product_List_Toolbar
whereas $this->getPagerHtml() in catalog/product/list.phtml means you are trying to call getPagerHtml() method of class Mage_Catalog_Block_Product_List where it is not present.
If you want to call $this->getPagerHtml() in list.phtml then first you need to create object of class Mage_Catalog_Block_Product_List_Toolbar in list.phtml

Example :

$object = new Mage_Catalog_Block_Product_List_Toolbar();
$object->getPagerHtml();

6
  • The class Mage_Catalog_Block_Layer_Product_List_Toolbar doesn't exists in catalog/product/list.phtml :(
    – CoalaArmy
    Dec 6, 2013 at 11:17
  • Sorry my mistake it's Mage_Catalog_Block_Product_List_Toolbar(); I have modified my answer. Dec 6, 2013 at 12:01
  • $object->getPagerHtml() echoes nothing. print_r($object) output is http://pastebin.com/zxAR8Xw8
    – CoalaArmy
    Dec 7, 2013 at 10:40
  • Also $object->getCollection() returns NULL. It should return the products collection, or not?
    – CoalaArmy
    Dec 7, 2013 at 10:50
  • No, it will not return you the product collection. Rather it will provide html for pager block. Dec 8, 2013 at 11:05
2

First get your product collection. For example, here the collection is $merged_collection. then apply the following code in the position where you want to place the pager and toolbar.

<?php  
$layout = Mage::getSingleton('core/layout');
$pager = $layout->createBlock('page/html_pager');
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($merged_collection);
$toolbar->setChild('product_list_toolbar_pager', $pager);
echo $toolbar->toHtml();
?>
1

Well, I wasnt able to find a way to get just the pager content, but I did find a way to show specific pieces of the toolbar, which contains the call to the pager.

In toolbar.phtml

Find the "sorter" div and wrap it like so:

<?php if (!$this->getHideSorter()) : ?>
*...sorter div stuff here...*
<?php endif; ?>

Similarly, find the "pager" div and wrap it like so:

<?php if (!$this->getHidePager()) : ?>
*...pager div stuff here...*
<?php endif; ?>

In list.phtml

You can add the pager like so:

<?php echo
$this->getToolbarBlock()->setHideSorter(true)->setHidePager(false)->toHtml();
?>

And you can add the sorter with this:

<?php echo 
$this->getToolbarBlock()->setHideSorter(false)->setHidePager(true)->toHtml();
?>

Or you could add both like this:

<?php echo 
$this->getToolbarBlock()->setHideSorter(false)->setHidePager(false)->toHtml();
?>

I would not have come to this solution without the help from another answer here on Stackexchange... Much props to @Marius (https://magento.stackexchange.com/users/146/marius) for his answer here:

How can I disable/remove the pager in toolbar above my product-grid?

1

For Magento 1.9 the only code that worked for me was the following:

$toolbarBlock = $this->getChild('product_list_toolbar');
$pagerBlock = $toolbarBlock->getChild('product_list_toolbar_pager');

$pagerBlock->setAvailableLimit($toolbarBlock->getAvailableLimit());

$pagerBlock->setUseContainer(false)
    ->setShowPerPage(false)
    ->setShowAmounts(false)
    ->setLimitVarName($toolbarBlock->getLimitVarName())
    ->setPageVarName($toolbarBlock->getPageVarName())
    ->setLimit($toolbarBlock->getLimit())
    ->setFrameLength(Mage::getStoreConfig('design/pagination/pagination_frame'))
    ->setJump(Mage::getStoreConfig('design/pagination/pagination_frame_skip'))
    ->setCollection($_productCollection);

echo $pagerBlock->toHtml();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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