i want to show root categories with image and description on home page content area. Basically i want show them as slides, each category scrolling with its image and description.

Please suggest


You need to create your own block, or at least one template.
Here is the short version using only a template.
Create the file app/design/frontend/base/default/template/homepage/categories.phtml with this content:

$rootId = Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToFilter('parent_id', $rootId)
    ->addAttributeToFilter('include_in_menu', 1) //this is needed if you want only the categories in the menu
    ->addAttributeToFilter('is_active', 1);

$_helper = $this->helper('catalog/output'); 
<?php if ($categories->count() > 0) : ?>
    <?php foreach ($categories as $category) : ?>
           <div class="name">
              <a href="<?php echo $category->getUrl()?>" title="<?php echo $this->escapeHtml($category->getName())?>"><?php echo $category->getName()?></a>
           <div class="image">
               <?php if ($category->getImageUrl()) :?>
                   <img src="<?php echo $category->getImageUrl()?>" alt="<?php echo $this->escapeHtml($category->getName())?>" />
               <?php endif;?>
           <div class="description">
               <?php echo $_helper->categoryAttribute($category, $category->getDescription(), 'description') ?>
    <?php endforeach;?>
<?php endif;?>

Now you need to add this to the homepage content:

{{block type="core/template" template="homepage/categories.phtml"}}

The markup of the template may need some modifications in order to make it a slider, but all the elements you need are there.

There is a cleaner method where you create you own block and move the code that retrieves the categories to a block method and call that method in the template. But the idea is the same.

I haven't tested the code so be careful at syntax errors.


Form Below Code you can got All The Root Category of Current Store.

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul id="nav">
    <?php foreach($_categories as $_category): ?>
            <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                <?php echo $_category->getName(); ?>
    <?php endforeach; ?>
<?php endif; ?>

with the Use of this code you can integrate with your slider as you want.


Go to CMS > Pages and select your home page from the backend.

Add this line

{{block type="core/template" template="custom/home_categories.phtml"}}

Then create a file named "home_categories.phtml" inside "custom" folder under your theme directory and add the following lines.

$categories = Mage::getModel('catalog/category')->load(2)->getChildren(); foreach(explode(',',$categories) as $category):



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.