2

I am wanting to include a larger than normal 'next page' type button in the list.phtml template whilst still having the normal pagination from pager.phtml

The function I'm wanting to use is found in code/core/Mage/Page/Block/Html/Pager.php:

public function getNextPageUrl()
    {
        return $this->getPageUrl($this->getCollection()->getCurPage(+1));
    }

This can be called in pager.phtml by performing $this->getNextPageUrl(). I'm wanting to call this function inside list.phtml but I'm not sure how to get it. Using $this->getNextPageUrl() doesn't work.

I've also tried variations of Mage::getModel('page/html_pager')->getNextPageUrl() without luck.

  • Did you try Mage::getBlockSingleton('page/html_pager')->getNextPageUrl()? – Mr_Green May 8 '14 at 5:10
2
+25

There are two ways of doing this. One is slightly easier than the other.

Add After getToolbarHtml call

If you do it after the call to getToolbarHtml in the list.phtml then the following code will work.

<?php echo $this->getChild('product_list_toolbar')->getChild('product_list_toolbar_pager')->getNextPageUrl() ?>

This is because the pager is actually inside the toolbar and not the list, see layout xml.

<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
    <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
        <block type="page/html_pager" name="product_list_toolbar_pager"/>

And most importantly the collection is setup in the toolbar's getPagerHtml function:

public function getPagerHtml()
{
    $pagerBlock = $this->getChild('product_list_toolbar_pager');

    if ($pagerBlock instanceof Varien_Object) {

        /* @var $pagerBlock Mage_Page_Block_Html_Pager */
        $pagerBlock->setAvailableLimit($this->getAvailableLimit());

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

        return $pagerBlock->toHtml();
    }

    return '';
}

Add before getToolbarHtml call

Or if you simply want to put it anywhere in the template what you can do is set the collection using the list`s collection with the following code.

$productCollection = $this->getLoadedProductCollection();
$pagerBlock = $this->getChild('product_list_toolbar')->getChild('product_list_toolbar_pager');
$pagerBlock->setCollection($productCollection);
echo $pagerBlock->getNextPageUrl();
1

This should give you the url you need. Simple as that. Works in category list pages and search results pages (advanced and quick):

$nextPage = $this
           ->getChild('toolbar')
           ->getChild('product_list_toolbar_pager')
           ->getPageUrl($_productCollection->getCurPage(+1));

Just make sure you use ti after this line:

$_productCollection=$this->getLoadedProductCollection();
0

This will give the URL of the next page, But when you will reach last page in pagination, it will show second last page means previous to last.

$productCollection = $this->getLoadedProductCollection();
$pagerBlock = $this->getChild('product_list_toolbar')->getChild('product_list_toolbar_pager');
$pagerBlock->setCollection($productCollection);
 echo $current_url = Mage::helper('core/url')->getCurrentUrl();
 $nextpageurl = $pagerBlock->getNextPageUrl();
 $prevpageurl = $pagerBlock->getPreviousPageUrl();
 if(strcmp($nextpageurl) == strcmp($current_url)){     
 echo $prevpageurl;
 }
 else{
echo  $nextpageurl = $pagerBlock->getNextPageUrl();
 }
0

I have worked on it for last day and find a way by which you can use the code anywhere in the product collection view to get the next page URL.

$productCollection = $this->getLoadedProductCollection();

echo $nextPage = $this->getChild('toolbar')->getChild('product_list_toolbar_pager') ->getPageUrl($productCollection->getCurPage(+1));
  • isn't this exactly what I just said? – Marius May 8 '14 at 6:21

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.