I have a block setup which will display the products for a category, such as this:

{{block  type="catalog/product_list" category_id="4" template="catalog/product/working-simple-list.phtml"}}

(I'm calling a custom list.phtml in the block so I can control the formatting etc). This block is then called from the category page.

The question is: how can I avoid having to manually enter the category_id? Currently, if I want to call this list.phtml on 5 categories, I need to create 5 unique block calls, setting the ID by hand for each category I want to show it on.

Much cleaner, simpler, would be have it automagically pull the ID, based on which page its called from. Then I would only need one block 'show custom list', and could call it from anywhere.

Any ideas?! Thanks.

1 Answer 1


You can create your own custom block type extending Mage_Catalog_Block_Product_List specifying the category if using $this->setCategoryId(..) method based on your custom logic.

Then you can just replace a type of the block in your {{block .. }} call with your new block type and remove category_id attribute.

  • Hi, thanks for your reply. This looks to be a bit beyond my current knowledge. Do you know any tutorial or guide you can point me to that can help with that? Thanks!
    – egg
    Jun 15, 2014 at 12:27
  • Googling for magento custom block returns some promising results. Jun 15, 2014 at 12:29
  • OK, thanks - I'll see what I can hack together and report back with a solution for others if/when I manage it :)
    – egg
    Jun 15, 2014 at 12:36
  • I've found what I think is a simple solution via: workingmagento.blogspot.de/2010/12/… Basically, in a category page, I call my customer product list page using this custom layout: <reference name="content"> <block type="catalog/product_list" name="product_list" template="catalog/product/working-simple-list.phtml"> </block> </reference> and it seems to work! On whatever page I put this, it pulls the required products - no need to specify the category ID. Please let me know if there is some downside to this? Thanks!!
    – egg
    Jun 15, 2014 at 13:24
  • So you put it on a category pages? Jun 15, 2014 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.