1

Here , Parent category is Chairs. & subcategories are modern, classic, patio, event....etc. Like this website: http://www.example.com

there are categories With images at the top under refine text

How to show these subcategory in category page with images in magento.

4
  • See my updated answer to get subcategoies with image May 12, 2017 at 6:16
  • are you got my answer? May 13, 2017 at 16:02
  • yes, second way is working May 15, 2017 at 5:52
  • hi, can u checked code once again, pls check echo $subcategory->getUrl() May 16, 2017 at 6:42

1 Answer 1

2

This will help to get child category with Image of every current category

app/design/frontend/package/theme/template/catalog/category/view.phtml

First Way: By current category:

<?php 
  $layer = Mage::getSingleton('catalog/layer');
  $_category = $layer->getCurrentCategory();
  $currentCategoryId= $_category->getId();
  $children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);
?>
<?php foreach ($children as $category): ?>
      <a href="<?php echo $subcategory->getUrl() ?>">
        <img src="<?php echo $subcategory->getImageUrl(); ?>" />
      </a>
<?php endforeach; ?>

Second Way: By category ID:

<?php
  $categoryId = 10 ;  // get current category id
  $category = Mage::getModel('catalog/category')->load($categoryId) ;
  $catList = explode(",", $category->getChildren();) ;
?>
<?php foreach($catList as $cat): ?>
     <?php $subcategory = Mage::getSingleton('catalog/category')->load($cat); ?>
     <a href="<?php echo $subcategory->getUrl() ?>">
        <img src="<?php echo $subcategory->getImageUrl(); ?>" />
     </a>
<?php endforeach; ?> 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.