1

I have to display category,subcategory and image on home page.I am using custom theme.

Foe example: My home page category,subcategory and image display is like below

Cat1 Cat2 Cat3
Subcat1 Image Subcat1 Image Subcat1 Image SubCat2 Subcat2 Subcat2 Subcat3 SUbcat3 Subcat3

Please help me how to do it.Its urgent please give me idea how to do it.

Many Thanks, Padma

  • I am using custom theme. – Padma G.C. Mar 13 '15 at 4:52
1

You could do something like this. Add a custom catalog/homecategories.phtml file and add it in your local.xml.

homecategories.phtml

$helper = Mage::helper('catalog/category');
/** @var $helper Mage_Catalog_Helper_Category */

$topCategories = $helper->getStoreCategories(true);
?>

<?php if (!empty($topCategories)): ?>
    <div class="home-categories">

        <ul class="level-1">
            <?php foreach ($topCategories as $topCategory): ?>
                <?php /** @var $topCategory \Mage_Catalog_Model_Category */ ?>
                <li>
                    <a href="<?php echo $helper->getCategoryUrl($topCategory); ?>"><?php echo $topCategory->getName(); ?></a>

                    <?php if ($topCategory->hasChildren()): ?>
                        <ul class="level-2">
                            <?php foreach ($topCategory->getCategories($topCategory, 0, true) as $category): ?>
                                <?php /** @var $category \Mage_Catalog_Model_Category */ ?>
                                <li>
                                    <a href="<?php echo $helper->getCategoryUrl($category); ?>"><?php echo $category->getName(); ?></a>
                                    <a href="<?php echo $helper->getCategoryUrl($category); ?>">
                                        <img src="<?php echo $category->getImageUrl();?>" alt="" />
                                    </a>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>

    </div>
<?php endif; ?>

<?php

local.xml

<cms_index_index>
    <reference name="content">
        <block type="core/template" name="home-categories" as="home_categories" before="-">
            <action method="setTemplate"><template>catalog/homecategories.phtml</template></action>
        </block>
    </reference>
</cms_index_index>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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