Magento Coding Solutions

Magento. Listing Sub-Categories On A Category Page

Step 1 .
 create a "Static Block"
 and put in Content area below code.
{{block type="core/template" template="catalog/category/sub.phtml"}}

  



Step 2.
create "sub.phtml" file in  "/your template/catalog/category/sub.phtml"
 <div class="category-products">

<ul class="products-grid">
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren());
$catDat =explode(',',$category->getChildren());
if(count($catDat)>0){
$categorycount = 0;
foreach($catDat as $catId){
$_category=Mage::getModel('catalog/category')->load($catId);

if($_category->getIsActive()){

if ($categorycount == 0){
$class = "first";
}elseif ($categorycount == 4){
$class = "last";
}else{
$class = "";
}
?>

<li class="item <?=$class?> catitm" align="center">
<div class="itemimg"><?php //echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>
<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><img src="<?php  echo $_category->getImageUrl(); ?>" alt="<?php echo $this->htmlEscape($_category->getName()) ?>"     style="width: 425px !important;height: 425px;"/></a>
</div>
<h3><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h3>
</li>

<?php

if($categorycount == 4){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid\">";
}else{
$categorycount++;
}


}


}

}?>

</ul>

</div>
Output is :



No comments:

Post a Comment