I'm having trouble displaying subcategory blocks in Magento. I have followed several solutions posted on here and this tutorial.

I created a static block with this code:

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

I also tried placing it in page/html/ as this was a solution I saw elsewhere.

Next I updated the settings on all top categories to:

Display mode: Static Block only

CMS Block: Sub Category Listing

Then I created the subcategory_listing.phtml file:

<div class="category-products">
<ul class="products-grid">
$categorycount = 0;
foreach ($_categories as $_category):
$layer = Mage::getSingleton('catalog/layer');
$catName = $this->getCurrentCategory()->getName();
if ($categorycount == 0){
$class = "first";
elseif ($categorycount == 3){
$class = "last";
$class = "";
<li class="item <?=$class?>">
<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><img src="<?php echo $_category->getImageUrl() ?>" 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>
if($categorycount == 3){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid\">";

and finally in app\code\local\Mage\Catalog\Block\Navigation.php I changed the getCurrentChildCategories() function to this:

public function getCurrentChildCategories()
        $layer = Mage::getSingleton('catalog/layer');
        $category   = $layer->getCurrentCategory();
        /* @var $category Mage_Catalog_Model_Category */
        $collection = Mage::getModel('catalog/category')->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
            ->addAttributeToFilter('is_active', 1)
            ->setOrder('position', 'ASC')

        $productCollection = Mage::getResourceModel('catalog/product_collection');
        return $collection;

This answer suggested it might be an issue with Magento caching static blocks, however disabling the cache on Blocks HTML makes no difference. Does anyone have a solution? is there an extension I can use instead?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.