Skip to content

Instantly share code, notes, and snippets.

@ceckoslab
Created August 15, 2012 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceckoslab/3359512 to your computer and use it in GitHub Desktop.
Save ceckoslab/3359512 to your computer and use it in GitHub Desktop.
Well formatted script for showing subcategories images in Magento
<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>
<?php if($_categories->count()):?>
<?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);
$catName = $this->getCurrentCategory()->getName();
// Test if the current category has an image assigned to it or not
if($_imageUrl=!$this->getCurrentCategory()->getImageUrl()): ?>
<?php /* Default subcategory jpg if no image exists */ ?>
<div class="category-box">
<a href="<?php echo $this->getCategoryUrl($_category)?>">
<img src="<?php echo $this->getSkinUrl('images/catalog/product/placeholder/thumbnail.jpg') ?>">
</a>
<p><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $catName ?></a></p>
</div>
<?php endif ?>
<?php if($_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
<?php /* Displays the subcategory image */ ?>
<div class="category-box">
<a href="<?php echo $this->getCategoryUrl($_category)?>">
<img src="<?php echo $_imageUrl?>" height="80">
</a>
<p><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></p>
</div>
<?php endif;
endif;?>
<?php endforeach ?>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment