Tuesday, October 15, 2013

Magento – Displaying Products in a Static Block

This is one of those ones that can be a bit frustrating, there’s many a tutorial out there that suggests you have to create a new template file and call that. It’s possible to call the standard catalog/product/view.phtml template from a static block but also pass parameters which dictate how it’s displayed. So you can add the following;

{{block type="catalog/product_list" name="product_list" category_id="3" column_count="6" 
count="6" limit="4" mode="grid" template="catalog/product/list.phtml"}}


And it will display the products using the default list template, with product numbers pulled from the System -> Configuration -> Catalog -> Frontend config.
Better still, you can copy that template and rename it as a custom template, take out a lot of the grid/list and toolbar conditionals and style it up the way you want, then just upload the new template file and apply that. You can use the template multiple times within the same static block, calling a catalogue category each time;
 
 
<h2>First Category</h2>
{{block type="catalog/product_list" name="product_list" category_id="1" column_count="6" 
count="6" limit="4" mode="grid" template="catalog/product/custom_list.phtml"}}

<h2>Second Category</h2>
{{block type="catalog/product_list" name="product_list" category_id="2" column_count="6" 
count="6" limit="4" mode="grid" template="catalog/product/custom_list.phtml"}}

<h2>Third Category</h2>
{{block type="catalog/product_list" name="product_list" category_id="2" column_count="6" 
count="6" limit="4" mode="grid" template="catalog/product/custom_list.phtml"}}


A really easy way to display all or portions of the full catalogue in a page, and control exactly how it’s displayed. Worked well for the site I’ve just finished, it had a ProNav mega menu so I used this technique to display the parent ‘Product’ page.

No comments:

Post a Comment