Changing the Magento product grid default

Written on July 24, 2013

Changing the default items-per-row in the Magento product grid from 3 to custom.

As I’m constantly told when working with Magento, it’s very bad practice to change the core files and that all changes should be applied to your theme. This way, when you run any updates to the core files – which you will do at some point – your custom changes will stay intact.

So to change the way that Magento shows the products in its grid view from the default number of 3, I added this to my app/design/frontend/custom_theme/default/layout/local.xml file:

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="content">
            <block type="catalog/product_list" name="home.catalog.product.list" as="products_homepage" template="catalog/product/list.phtml">
                <action method="setColumnCount"><columns>7</columns></action>
            </block>
        </reference>
    </default>
</layout>

This obviously changed the number of items from 3 to my custom amount of 7.

I’m pretty sure (not tested yet) that this will load on each and every page, as opposed to just my intended homepage template but it works perfectly fine. I am looking into ways of improving this so if you have any other suggestions then I’m all ears. For example, I would like this to just load for my custom homepage (page_homepage) layout handle.

I tried adding page_homepage into my action method but that was unsuccessful.

Update

It turns out that it’s a simple as:

<!--?xml version="1.0"?-->
<layout>
    <page_homepage>
        <reference name="content">
            <block type="catalog/product_list" name="home.catalog.product.list" as="products_homepage" template="catalog/product/list.phtml">
                <action method="setColumnCount"><columns>7</columns></action>
            </block>
        </reference>
    </page_homepage>
</layout>

So instead of using default, simply wrap it in the layout handler for your page, which in my case was page_homepage.

Thanks to @Josh__Taylor