tags:

views:

283

answers:

2

I would like to create a subordinate set of CMS pages in Magento so that the breadcrumb navigation at the top of the page looks like this:

Home > Parent CMS Page > Child CMS Page

Even though I can specify a hierarchical relationship with the URL key field, it seems to be that all CMS pages in Magento are listed in the root directory by default:

Home > Child CMS Page

Any ideas?

A: 

You are right, there is no hierarchy of CMS pages in Magento. The best solution would be to create a real hierarchy by adding a parent_id to CMS pages and modifying the CMS module to handle nested URLs and breadcrumbs. But that requires a lot of coding.

A quick-and-dirty hack is to modify the breadcrumbs manually on each subpage by adding something like this to the layout update XML:

<reference name="root">
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
    <action method="addCrumb">
        <crumbName>home</crumbName>
        <crumbInfo><label>Home page</label><title>Home page</title><link>/</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>myparentpage</crumbName>
        <crumbInfo><label>My Parent Page</label><title>My Parent Page</title><link>/myparentpage/</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>mysubpage</crumbName>
        <crumbInfo><label>My Sub Page</label><title>My Sub Page</title></crumbInfo>
    </action>
</block>
</reference>
Anders Rasmussen
Thanks! This is exactly what I did and, while it is still only a manual override, it works flawlessly.
Jason
A: 

I had the same problem with breadcrumbs and cms pages a few days ago check here ->

Similar to Anders Rasmussen post I edited every cms page manually

In breadcrumbs.phtml I added a little condition to define if a Page is a CMS page (thanks to Alan Storm) and remove standard crumb(s) and added new crumbs via xmllayout.

<?php
        if($this->getRequest()->getModuleName() == 'cms'){
            unset($crumbs['cms_page']);
        }
?>

xml:

<reference name="breadcrumbs">

<action method="addCrumb">
     <crumbName>cms_page_1st_child</crumbName>
    <crumbInfo><label>1st child</label><title>1st child</title><link>/1st child/</link></crumbInfo>
</action>

<action method="addCrumb">
     <crumbName>cms_page_2nd_child</crumbName>
    <crumbInfo><label>2nd child</label><title>2nd child</title></crumbInfo>
</action>

</reference> 

hope that helps, Rito

Rito