1 min read

How to display category images in Magento static cms page

Follow the code which show images of sub category in static cms page.

<?php

$_categories=$this->getCurrentChildCategories() ?>

<?php if($_categories->count()): ?>
<ul class=”category-links”>
    <?php foreach ($_categories as $_category): ?>
        <?php if($_category->getIsActive()):

             $cur_category=Mage::getModel(‘catalog/category’)->load($_category->getId());
             $layer = Mage::getSingleton(‘catalog/layer’);
             $layer->setCurrentCategory($cur_category);
             //$_imageUrl = $this->getCurrentCategory()->getImageUrl();

         ?>
        <li class=”<?php echo $this->htmlEscape($_category->getUrlKey()) ?>”>
            <?php if($_imageUrl = $this->getCurrentCategory()->getImageUrl()){?>
            <img src=”<?php echo $_imageUrl; ?>” alt=”<?php echo $this->htmlEscape($_category->getName()) ?>” />
            <? } else {?>
            <img src=”<?php echo $this->getSkinUrl(‘images/add-01.gif’)?>” alt=”<?php echo $this->getCurrentCategory()->getName();?>”>
            <? } ?>
           <a href=”<?php echo $this->getCategoryUrl($_category) ?>”>
              <?php echo $this->htmlEscape($_category->getName()) ?>
           </a>
        </li>
        <?php endif; ?>
    <?php endforeach ?>
</ul>
<? endif; ?>

Share your Love

Leave a Reply

Your email address will not be published. Required fields are marked *