Magento 类别页面:将特定类别的布局从网格模式更改为列表模式
我希望某些类别页面处于列表模式并开始显示 30 个项目,但我希望另一个类别页面处于网格模式并显示较少的项目。
我知道我可以通过管理面板更新自定义布局 xml 来做到这一点,但我不确定确切的 XML 是什么。
I want some category pages to be in the list mode and to start with 30 items displayed but I want another category page to be in grid mode and with fewer items displayed.
I understand that I can do this by updating the custom layout xml through the admin panel, but I'm not sure what the exact XML would be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的解决方案是创建一个覆盖 Toolbar 类的模块,该类控制目录的网格/列表视图以及要显示的项目数。
要覆盖的特定类称为
Mage_Catalog_Block_Product_List_Toolbar
。克隆该文件并向其中添加以下方法:您还需要为其创建一个 config.xml 文件。
现在,在管理面板中,要更改类别的布局,请转到目录>;管理类别并选择您想要更改的类别。转到自定义设计选项卡,并在标有自定义布局更新的字段中输入以下 XML 代码:
当然,请记住刷新 Magento 的布局缓存,否则您的更改将失败不出现。
My solution was to create a module that overrides the Toolbar class which is what controls the grid/list view of the catalog and the number of items to display.
The specific class to override is called
Mage_Catalog_Block_Product_List_Toolbar
. Clone the file and add the following method to it:You also need to create a config.xml file for it.
Now, in the admin panel, to change the layout of a category, go to Catalog > Manage Categories and select the category that you wish to change. Go to the Custom Design tab and in the field labelled Custom Layout Update, enter the following XML code:
Of course, remember to flush the layout caches of Magento or your change won't appear.
我知道有点晚了,但即使没有直接通过布局 XML 或管理中的“自定义布局更新”部分重写,这也可以工作:
请参阅:https://stackoverflow.com/a/25803228/1918829
I know it's a little late, but this works even without rewrites directly via the layout XML or the "Custom Layout Update" section in admin:
See: https://stackoverflow.com/a/25803228/1918829
复制list.phml并将其重命名为grid.phtml,然后:
更改
为
然后将块添加到CMS页面:
Duplicate the list.phml and rename it to grid.phtml and then:
change
to
and then add the block to CMS page: