开发者

Magento Category Pages: Change layout of specific categories from grid mode to list mode

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 wit开发者_如何学Goh 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.


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:

/**
 * Sets the current View mode (grid, list, etc.)
 *
 * @param string $mode
 */
public function setCurrentMode($mode)
{
    $this->setData('_current_grid_mode', $mode);
}

You also need to create a config.xml file for it.

<!-- app/code/local/Example/Catalog/etc/config.xml -->
<?xml version="1.0"?>
<config>
  <global>
    <blocks>
      <catalog>
        <rewrite>
          <product_list_toolbar>Example_Catalog_Block_Product_List_Toolbar</product_list_toolbar>
        </rewrite>
      </catalog>
    </blocks>
  </global>
</config>

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:

<reference name="product_list_toolbar">
  <action method="setCurrentMode">
    <mode>list</mode>
  </action>
</reference>

Of course, remember to flush the layout caches of Magento or your change won't appear.


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:

<reference name="product_list_toolbar">
    <action method="setData"><key>_current_grid_mode</key><value>list</value></action>
</reference>

See: https://stackoverflow.com/a/25803228/1918829


Duplicate the list.phml and rename it to grid.phtml and then:

change

<?php if($this->getMode()!='grid'): ?>

to

<?php if($this->getMode()!='list'): ?>

and then add the block to CMS page:

 {{block type="catalog/product_list" category_id="152" template="catalog/product/grid.phtml"}}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜