Magento工具栏不显示寻呼机


Magento toolbar not rendering pager

我是Magento的新手,我很难弄清楚如何在工具栏内显示从目录/类别/视图调用的分页器。phtml文件。下面是我使用的代码:

$layout = Mage::getSingleton('core/layout');
$toolbar = $layout->createBlock('catalog/product_list_toolbar');
$pager = $layout->createBlock('catalog/html_pager');
$block = $layout->createBlock('catalog/product_list');
$block->setCategoryId($_category->getId());
$block->setChild('toolbar', $toolbar);  
$collection = $block->getLoadedProductCollection();
$toolbar->setCollection($collection);
echo $toolbar->renderView(); 

Sort By, Show items per page和items total显示正确,但是分页器只是不呈现。有人知道我哪里做错了吗?

你有两个问题我马上就能发现

  1. 没有catalog/html_pager这样的块类型(你是说page/html_pager吗)

  2. 工具栏块的getPagerHtml方法查找名为product_list_toolbar_pager的子块。您没有插入、追加或设置子节点。

用下面的代码实例化分页块

$pager = $layout->createBlock('page/html_pager');

,然后用

插入工具栏
$toolbar->setChild('product_list_toolbar_pager', $pager);

,你可能会有更好的结果。

同样,分页模板本身(frontend/base/default/template/page/html/pager.phtml)包含的代码将在只有一页结果的情况下抑制页面。在这个if子句周围进行一些调试。

<!-- File: app/design/frontend/base/default/template/page/html/pager.phtml -->
<?php if($this->getLastPageNum()>1): ?>

以确保您不会与小类别列表发生冲突。