Quantcast
Viewing latest article 2
Browse Latest Browse All 2

How to display categories with images on homepage?

You will need to add a static block within your CMS homepage, just how we learned in our earlier post How to call a static block inside a CMS page? This static block looks something like this:

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}

After you’ve called the static block within the page you will need to create the file list.phtml under “app/design/frontend/default/default/template/catalog/category/list.phtml” ( or you can put it under your own theme, instead of default/default you can use default/yourthemename ).

This file, list.phtml has to look something like this:

<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $open = $this->isCategoryActive($_category); ?>
<?php
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
if ($immagine = $this->getCurrentCategory()->getImageUrl()):
?> <div style="float: left; padding-right: 30px; text-align: center;">
<div class="category">
<p>
<a href="<?php echo $this->getCategoryUrl($_category)?>">
<img src="<?php echo $immagine ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="200" height="200" />
<?php echo $_category->getName()?>
</a>
</p>
</div>
</div> <?php endif; ?>
<?php endforeach; ?>

After you’ve done this you have to make sure that:

1) you upload image to your category.
2) add the static block call ( {{block type=”catalog/navigation” name=”catalog.category” template=”catalog/category/list.phtml”}} ) within your code editor by clicking show / hide editor.
3) clear the cache!

Related Posts:


Viewing latest article 2
Browse Latest Browse All 2

Trending Articles