Magento – how to display product with category name on cms page in magento

categorymagento-1.9product

I have a one cms page with name stock list and i want to show here all the product with the corresponding category name above it. like this

category 1

product1 product2 proudct3

category2
proudct1 product2 product3

I tried

{{block type="catalog/product_list" category_id="8" template="catalog/product/featured.phtml"}} 

but this will only show the product from a specific category not does not print the name of the category

I have around 50 category so it is not a good practice for me to do this type of coding again and again to show product from all the category.

so I think that one solution for this is to call the view.phtml file which is used to show product on category page. but i don't know the code how to call that file on cms page. so can any one help me in this or give me the better idea for this problem

Best Answer

I'm not sure where your template file featured.phtml is coming from, as it seems not the be a Magento core file.
But you can use your own template file (other then featured.phtml) and make sure it outputs the category name of the called category (referenced by category_id="8").

Copy your featured.phtml and add a line to output the category's name. As your block type is catalog/product_list look at the file app/code/core/Mage/Catalog/Block/Product/List.php to get a clue how you can achive this. As you can see in line 79 you can get the referenced category ID by $this->getCategoryId().

So a

<?php echo Mage::getModel('catalog/category')->load($this->getCategoryId())->getName() ?>


would do the trick inside you template file. The layout is up to you.

This is from Vinai's reply on https://stackoverflow.com/questions/9534236/how-to-get-the-category-name-from-list-phtml-in-magento

Related Topic