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 Answers
$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();
-
The class
Mage_Catalog_Block_Layer_Product_List_Toolbar
doesn't exists incatalog/product/list.phtml
:( Commented Dec 6, 2013 at 11:17 -
Sorry my mistake it's Mage_Catalog_Block_Product_List_Toolbar(); I have modified my answer. Commented Dec 6, 2013 at 12:01
-
$object->getPagerHtml()
echoes nothing.print_r($object)
output is http://pastebin.com/zxAR8Xw8 Commented Dec 7, 2013 at 10:40 -
Also
$object->getCollection()
returnsNULL
. It should return the products collection, or not? Commented Dec 7, 2013 at 10:50 -
No, it will not return you the product collection. Rather it will provide html for pager block. Commented Dec 8, 2013 at 11:05
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();
?>
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?
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();
$this->getpagerhtml()
is accesible in\template\catalog\product\list\toolbar.phtml
, but in thelist.phtml
it shows nothing.toolbar.phtml
, but I need the inlist.phtml
. If I write the pager functions inlist.phtml
then they show nothing.