user1735921
user1735921

Reputation: 1389

How to display a list of all categories on the home page

I want to display a list of all categories on the home page as links, so when someone clicks then they go that page.

I tried something like this: I put this code on content of cms -> home page

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/view.phtml"}}


{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}

But it displays nothing.. my home page becomes blank, when I put only this:

   {{block type="catalog/navigation" name="catalog.category" template="catalog/category/view.phtml"}}

then all products are displayed correctly..

Upvotes: 1

Views: 4177

Answers (2)

Steve Sims
Steve Sims

Reputation: 1

I've used the following code in the wysiwyg editor to achieve the above

{{block type="catalog/navigation" name="catalog.category" template="catalog/product/mycatt.phtml"}}

It seems to work well.

Upvotes: 0

Chris Rogers
Chris Rogers

Reputation: 1522

Depending on where you wish to place these links, there are many ways to achieve this.

Adding categories to the content

if you wish to place category links in the content of the homepage then this can be achieved easily by heading to CMS > Pages > Homepage: Design tab and adding the following to Layout update XML:

<reference name="content">
    <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
        <label>Navigation Bar</label>
        <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml">
            <block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
        </block>
   </block>
</reference>

Then you would have to style it to your liking (to avoid the duplicate menu look).

Adding categories to the sidebar

If your homepage follows a multi-column layout and you wish to add the links to one of the sidebars then this is a little more tricky.

The best way would be to create your own module here. After head to app/design/frontend/yourpackage/yourtemplate/layout/ and add the following to your xml layout:

<default>
    <reference name="left">
        <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
            <label>Navigation Bar</label>
            <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml">
                <block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
            </block>
       </block>
    </reference>
</default>

Depending on what layout your homepage conforms to you would replace the default tag with page_two_columns_left, page_two_columns_right, page_three_columns etc. Again you'll have to style it to your liking.

I hope this helps

Upvotes: 1

Related Questions