0
votes

I want to show sub sub categories in my magento static block.

For example there is Women category on that page. I want to show all subcategories of women, and the sub categorie of this.

Structure on women page will be

Category 1 -> sub 1 -> Sub 1

I have already implemented some code but it dont show sub categories:

<?php 
//If there are sub categories
$categories = $this->getCurrentChildCategories();
$categoriescount = $this->getCurrentChildCategories()->count();
if ($categoriescount > 0): 
?>
<div class="sub-category-container">    
    <?php 
    //Loop through categories
    foreach ($categories as $category):
    ?>
    <div class="sub-category">
        <a href="<?php echo $this->getCategoryUrl($category)?>" class="cat-image">
        <?php 
        // If there is a thumbnail set for the category - Display it
        if($imgUrl = Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()):?>
        <img src="<?php echo $this->getBaseUrl()."media/catalog/category/".$imgUrl ?>" width="220" height="110" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
        <?php endif; ?>
        </a>
        <div class="inner-sub-category">
            <a href="<?php echo $this->getCategoryUrl($category)?>" class="sub-link"><?php echo $category->getName()?></a>
            <a href="<?php echo $this->getCategoryUrl($category)?>" class="btn"><span>View All</span></a>
        </div>
    </div>

    <?php endforeach; ?>
</div>
<?php else:?>
<p>No Sub Categories</p>
<?php endif; ?>

Output of above code http://prntscr.com/6wcfov

2

2 Answers

0
votes

Check out the getCategories() method in the Categories model.

$subcategories = Mage::getModel('catalog/category')->getCategories($parentCategory->getId());
foreach ($subcategories as $subcategory) {
    ...do things
}

You can do this recursively to get all the subcategories in a parent category.

0
votes

Display SubCategory of current category

    $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getId());

$subCategories = explode(',', $loadCategory->getChildren());

foreach ( $subCategories as $subCategoryId )
{
    $cat = Mage::getModel('catalog/category')->load($subCategoryId);

    if($cat->getIsActive())
    {
        echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a>';
    }
}