11

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.

2 Answers 2

6

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>
1
  • I noticed that you can also add this: {{block type="core/template" template="catalog/homecategories.phtml"}} to any static block to display main categories anywhere. However this does not show sub categories and I need that too.
    – Webninja
    Commented Feb 13, 2018 at 10:48
1

Create a static block from admin Then

create a local.xml file under app/design/frontend/yourpackage/yourtemplate/layout and past the below code

  <?xml version="1.0"?>
        <layout version="0.1.0">
        <catalog_category_layered>

                <reference name="category.products">
                    <block type="cms/block" name="cat_static_block" >
                        <!--
                            The content of this block is taken from the database by its block_id.
                            You can manage it in admin CMS -> Static Blocks
                        -->
                        <action method="setBlockId"><block_id>yourblock_id</block_id></action>
                    </block>
                </reference>
        </catalog_category_layered>
           <catalog_category_default>

                <reference name="category.products">
                    <block type="cms/block" name="cat_static_block" >
                        <!--
                            The content of this block is taken from the database by its block_id.
                            You can manage it in admin CMS -> Static Blocks
                        -->
                        <action method="setBlockId"><block_id>yourblock_id</block_id></action>
                    </block>
                </reference>
        </catalog_category_default>
    </layout>

and goto app/design/frontend/yourpackage/yourtemplate/template/catalog/category/view.phtml add code <?php echo $this->getChildHtml('cat_static_block');?>

3
  • sorry where do i create this local.xml ? and what do i put in my static block content in admin ??
    – Adam Allen
    Commented Jul 31, 2014 at 14:45
  • yes,you need cms static block from admih...
    – Amit Bera
    Commented Jul 31, 2014 at 14:51
  • i have created a Static block with the ID all_cat_home but i need to put something in the content filed on the admin page. What do i write in there?
    – Adam Allen
    Commented Jul 31, 2014 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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