【问题标题】:Magento toolbar not rendering pagerMagento 工具栏不呈现寻呼机
【发布时间】:2013-04-10 19:52:25
【问题描述】:

我是 Magento 的新手,当从 catalog/category/view.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(); 

排序方式,每页显示项目和项目总数显示得当,但寻呼机只是没有呈现..有人知道我做错了什么吗?任何帮助将不胜感激。

【问题讨论】:

    标签: magento toolbar pager php


    【解决方案1】:

    你有两个问题我可以立即发现

    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): ?>
    

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

    【讨论】:

    • 非常感谢!它现在正在工作。我使用的主题似乎已经有了 getLastPageNum()>1): ?> 案例,但感谢您指出这一点。
    猜你喜欢
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多