List Sub Categories on Magento Category Pages

fter reading this most I revised the code to get the layout matching the grid layout in Magento 1.5: http://www.magentocommerce.com/boards/viewreply/162813/

1. In cms select Static Blocks

  • Set the Block Identifyer to for example “Sub Category Listing”
  • Set the Identifyer to “subcategory_listing”
  • In the content section write:

{{block type="catalog/navigation" template="catalog/navigation/subcategory_listing.phtml"}}

2. Now take the code below and paste it into a new file called "subcategory_listing.phtml" this file needs to live in the "catalog/navigation" directory:

<div class="category-products">
<ul class="products-grid">
<?php
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
$categorycount = 0;
foreach ($_categories as $_category):
if($_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$catName = $this->getCurrentCategory()->getName();
if ($categorycount == 0){
$class = "first";
}
elseif ($categorycount == 3){
$class = "last";
}
else{
$class = "";
}
?>
<li class="item <?=$class?>">
<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><img src="<?php echo $this->getCurrentCategory()->getThumbnailUrl() ?>" width="100" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" /></a>
<h2><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h2>
</li>
<?php
endif;
if($categorycount == 3){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid\">";
}
else{
$categorycount++;
}
endforeach;
endif;
?>
</ul>
</div>

3. Now Goto Manage Categories.

  • Pick a Category whose subcategories you’d like displayed
  • Set the display mode to “Static Block Only” or “Static Block and Products”
  • From the CMS Block dropdown select the Static Page “Sub Category Listing”

Important!! You must do this unless Magento have introduced getThumbnailUrl():

http://www.magentocommerce.com/boards/viewreply/308847/

About Keiron

Web Developer based in the UK. Click here if you want to work with me