0
votes

I have a category like music which has no products immediately under it on my magento site. So this how my category structure looks.

music (0)

---|_ genre (0)

------|_POP(3)

------|_R&B(4)

---|_Artists(0)

------|_Rihanna(4)

---|_Critics Choice(9)

So now is there any way i can retrieve all the children category products when i am on music or genre?!?

Any help would be appreciated

Thanks

1

1 Answers

0
votes

I have done this in the past by creating a template within my theme called subcategorylist.phtml in template/catalog/product/

    <ul class="list">
    <?php
    $currentCat = Mage::registry('current_category');

    $subCats = $currentCat->getChildren();


    foreach(explode(',',$subCats) as $subCatid)
    {
            $_category = Mage::getModel('catalog/category')->load($subCatid);
            if($_category->getIsActive())
            {
                    $catUrl = $_category->getURL();
                    $catName = $_category->getName();

                    if($_category->getImageUrl())
                    {
                            $catimg = $_category->getImageUrl();
                    }

                    echo '<li><a href="'.$catUrl.'" title="View the products for this category"><img src="'.$catimg.'" alt="'.$catName.'" /></a>';
                    echo '<h2><a href="'.$catUrl.'" title="View the products for this category">'.$catName.'</a></h2></li>';

            }
    }

    ?>
    </ul>

then within magento backend in CMS -> Static blocks add a new block called Categories with the following code

 {{block type="catalog/product" template="catalog/product/subcategorylist.phtml"}}

Then you can go to the particular category you wish to implement this on go to display settings and select the Categories block from the CMS Block drop down.