I am creating navigation for my store. I am new to magento. I am having problem to load product under that category. It is possible for me to print all product under all categories but I dont know how to load products under its specific category.
This is 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')->getCategories(2);?>
<ul class="content-navigation">
<?php foreach($children as $category){ ?>
<li>
<a href="<?php echo $category->getUrlPath(); ?>"><?php echo $category->getName();?></a>
<?php $category = Mage::getModel('catalog/product')->load($category->getId()); //Pass category ID here.
$productCollection = $category->getProductCollection();?>
<ul>
<?php foreach($productCollection as $product){ ?>
<li><a href="#"><?php echo $product->getName(); ?></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; ?>
EDIT
<div class="block-content">
<?php $children = Mage::getModel('catalog/category')->getCategories(2);?>
<ul class="content-navigation">
<?php foreach($children as $category){ ?>
<li>
<a href="<?php echo $category->getUrlPath(); ?>"><?php echo $category->getName();?></a>
<?php $categoryId = $category->getId(); ?>
<?php $category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addCategoryFilter($category)
->load();
?>
<ul>
<?php foreach($products as $product){ ?>
<li><a href="#"><?php echo $product->getName(); ?></a></li>
<?php }?>
</ul>
</li>
<?php } ?>
</ul>
</div>