Magento: Display category & sub-category with thumbnail

<?php $_helper = Mage::helper('catalog/category') ?>
	<?php $_categories = $_helper->getStoreCategories() ?>
	<?php if (count($_categories) > 0): ?>
		<?php foreach($_categories as $_category): ?>
  <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                <?php echo $_category->getName() ?>
            </a>
				<?php $_category = Mage::getModel('catalog/category')->load(11) ?>
				<?php $_subcategories = $_category->getChildrenCategories() ?>
				<?php if (count($_subcategories) > 0): ?>
				<ul>
			        <?php foreach($_subcategories as $_subcategory): ?>
					<li>
						<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
		                	<?php echo $_subcategory->getName() ?>
							<?php echo '<img src="' . Mage::getBaseUrl('media').'catalog/category/'. Mage::getModel('catalog/category')->load($_subcategory->getId())->getThumbnail() . '" />'; ?>
						</a>
	                </li>
	            	<?php endforeach; ?>
	        	</ul>
			<?php endif; ?>
		<?php endforeach; ?>
	<?php endif; ?>

The above code list the subcategories that is inside category id 11. For to get the thumbnail of category we need to upload image while creating the categories

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: