0
votes

what should be the code in phtml file to show one specific subcategory product on home page ?

I have created a file in catalog/product/topSection.phtml with following code-

             <?php

                $cat_id = 42;
                $category = Mage::getModel('catalog/category')->load($cat_id);
                $products = $category->getProductCollection();
                echo 'total- '.$products->count();
                foreach($products as $product){ ?>


                <h3>
                  <img src="<?php echo $product->getImageUrl() ?>" alt="">
                  <p><?php echo $product->getName()  ?></p>
                </h3>

            <?php }?>

and used

{{block type="core/template" name="top.section.home" template="catalog/product/topSection.phtml"}}

in home page content. but nothing is displaying. what is wrong in my code.

1
Did you make sure that the products called and category are in the right store view scope ? also check this it might help stackoverflow.com/questions/10794046/… - Rabea

1 Answers

0
votes

I checked your code it is working and also display product. First please check category id and sure category is enable ?