Tuesday, 4 September 2012

Display all sub category product when click main category in magento?


app/design/frontend/packagename/themeanme/template/catalog/category/view.phtml

put below code after  this code

<div class="page-title category-title">
    <?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
        <a href="<?php echo $this->getRssLink() ?>" class="link-rss"><?php echo $this->__('Subscribe to RSS Feed') ?></a>
    <?php endif; ?>
    <h1><?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></h1>
</div>
----------------------------- code Start here----------------------------------
<?php $_category  = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper     = Mage::helper('catalog/category');
?>
  
  
    <?php
$i=1;
?>
<ul>
<?php
foreach ($collection as $category){ //Loop through the categories
?>

 <li style="float:left; margin-right:5px;">
 <?php
    $subCategory = Mage::getModel('catalog/category')->load($category->getId());
    //Get the child category models
   $imgSrc = $subCategory->getImageUrl(); //Get the image url
   if($imgSrc){
    ?>
 

  <a href="<?php echo $subCategory->getUrl();?>"><img src="<?php echo $imgSrc; ?>"  height="100" width="150"/></a><br/>
  <a href="<?php echo $subCategory->getUrl();?>"><?php echo $subCategory->getName();?></a>
  </li>
  <?php if($i%3==0){?>
  </ul><ul>
  <?php }$i++;?>

  <?php
   }}
   ?>
    </ul>

1 comment:

  1. Want to display like this how to edit catalog/product/list.phtml ?
    Subcategory 1 product 1 of sub category 1 product 2 of sub category 1 product3 of sub category 1

    Subcategory 2

    product 1 of sub category 2 product 2 of sub category 2 product3 of sub category 2

    ReplyDelete

Note: only a member of this blog may post a comment.