I an newbie to Magento. I want to load only one category in my category navigation. That root category ID is (2). I want load all the sub-categories under that root categories. and under sub-category all the product that category have. And code is working fine but its loading all the menu and categories i have in my magento website.
My Code
<?php $_menu = $this->renderCategoriesMenuHtml($this->getSelectedCategoryId(), 0, 'level-top') ?>
<?php
if ($this->getTitle() != '') {
$title = $this->getTitle();
} else {
$title = 'Categories';
}
?>
<?php
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
?>
<?php if ($_menu): ?>
<div class="block vertical-menu">
<div class="title-block" style="margin-bottom:0px;"><h4><?php echo $this->__($title) ?></h4></div>
<div class="block-content">
<?php $children = Mage::getModel('catalog/category')->getCollection(2)
->addAttributeToSelect('name')
->addAttributeToSelect('is_active')
->addUrlRewriteToResult();?>
<ul class="content-navigation">
<?php $childGroup = 0; ?>
<?php foreach($children as $category){ ?>
<li id="menu-item-<?php echo $category->getId(); ?>">
<?php
$childGroup= $childGroup + 1;
?>
<a href="<?php echo $category->getUrl($category); /* $childGroup; echo $category->getUrl($category) */ ?>"><?php echo $category->getName();?></a>
<span class="toggle-icon"><a class="toggle-icon-me" href="#child-group-<?php echo $childGroup ?>" role="button" data-toggle="collapse"
area-expanded="false" area-controls="#child-group-<?php echo $childGroup ?>"></a></span>
<?php $categoryId = $category->getId(); ?>
<?php $category = Mage::getModel('catalog/category')->load($categoryId);
$products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($category)
->addAttributeToSelect('*');
?>
<ul id="child-group-<?php echo $childGroup; ?>" class="collapse">
<?php foreach($products as $product){ ?>
<li id="product-<?php echo $product->getId(); ?>"><a href="<?php echo $product->getUrlPath(); ?>" style="padding-left:25px;"><span style="font-size: 11px;"><?php echo $product->getName(); ?></span></a></li>
<?php }?>
</ul>
</li>
<?php } ?>
</ul>
</div>
</div>
<?php else: ?>
<?php if (Mage::helper('mpanel')->acceptToUsePanel()): ?>
<div class="block vertical-menu">
<div class="block-title"><strong><span><?php echo $this->__($title) ?></span></strong></div>
<div class="block-content">
<p><?php echo $this->__('Have no categories.'); ?></p>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
What is wrong with my code?