Display Store Categories On HomePage In Magento

Display All Magento Category On HomePage With Image

Sometime we need to display webstore categories with there images on homepage, its very simple to do it
just create a page call it hopepage.phtml then go to magento backend and call cms block.
Paste the code below to your homepage.phtml file.

[php]
<div class="top-home-category">

<?php
$limit = 0;
$_helper = $this->helper(‘catalog/output’);
foreach ($this->getStoreCategories() as $_category):

if($_category->getIsActive()):

$cur_category = Mage::getModel(‘catalog/category’)->load($_category->getId());

if ($_imgUrl = $cur_category->getImageUrl()){

$_imgHtml = ‘<img src="’.$_imgUrl.’" alt="’.$this->htmlEscape($cur_category->getName()).’" title="’.$this->htmlEscape($cur_category->getName()).’" width="105px" />’;
$_imgHtml = $_helper->categoryAttribute($cur_category, $_imgHtml, ‘image’);
} ?>
<div class="home-category">
<div class="linkimage">
<a href="<?php echo $this->getCategoryUrl($cur_category) ?>" style="border:none">
<?php echo $_imgHtml; ?>
</a>
</div>
<div class="category-link-container">
<a href="<?php echo $this->getCategoryUrl($cur_category) ?>">
<?php echo $_helper->categoryAttribute($cur_category, $cur_category->getName(), ‘name’) ?>
</a>
</div>
</div>

<?php
$limit+=1;
endif;

if ($limit==8):
break;
endif;

endforeach;
?>
</div>
[/php]

Leave a Comment

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

*