Showing posts with label category list. Show all posts
Showing posts with label category list. Show all posts

Friday, 18 May 2012

Magento: Create Category List with Images

Magento: Create Category List with Images

The code to create a list of top-level categories along with their images:
<?php $_categories = $this->getStoreCategories() ?>
<?php $count = 0 ?>
<ul id="square-category">
<?php foreach ($_categories 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);
$immagine = $this->getCurrentCategory()->getThumbnail()
?>

<?php $count = $count+1 ?>
    <li class="Pos<?php echo $count ?>">
        <a href="<?php echo $this->getCategoryUrl($_category) ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
            <img src="/media/catalog/category/<?php echo "$immagine" ?>" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" class="category-img" />
            <span><?php echo $this->htmlEscape($_category->getName()) ?></span>
        </a>
    </li>
<?php endforeach; ?>
</ul>