Magento – How to create a static block which displays all categories

categorystatic-block

I want to create a static block which displays all of my categories and displays them in a list. I don't need an image and I don't need the sub categories.

Then I want to add this block to my home page.

Best Answer

Create one .phtml file inside app/design/frontend/your_theme/default/template/catalog lets name it as homecategories.phtml and paste this code into it

  <!-- Categories display start -->
        <div class="home_categories">
              <ul>
                   <?php $helper = $this->helper('catalog/category') ?>
                 <?php foreach ($helper->getStoreCategories() as $_category): ?>
                 <li>
                     <a href="<?php echo Mage::getModel('catalog/category')->setData($_category->getData())->getUrl(); ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a>
                 </li>
                 <?php endforeach ?>
              </ul>

        </div>
         <?php echo $this->getChildHtml() ?>

        <!-- Categories display end -->

now create a static block lets name it as homecategories id as home_categories and now place this code into content of that block {{block type="core/template" template="catalog/homecategories.phtml"}} now call this static block in your cms.xml in this way

<block type="cms/block" name="homecategories">
   <action method="setBlockId"><block_id>home_categories</block_id></action>
</block>