Magento, an open-source PHP ecommerce solution, has a very comprehensive feature list. However, its built-in CMS doesn’t support hierarchical pages. You can fake it, though.
Let’s say you have a page with an SEF (search engine friendly) URL Identifier of “foo”. You’d like to have a subpage “bar” nested under foo. The CMS doesn’t let you create parent-child relationships, but Magento will let you include forward slashes in the SEF URL Identifier so that it is “foo/bar”.
That’s the good news. The bad news is if you want to use the breadcrumbs block, it won’t work out of the box. The Magento CMS is flat, so the default breadcrumbs will always look like “Home / My Page Title.” The optimal solution is to override the breadcrumbs module and parse the SEF URL Identifier and construct the breadcrumbs from that. (I may write a post about it in the future so stay tuned.) The good news for those designers out there, you don’t have to dive into code.
Magento’s CMS has a feature where each page has a way to override its XML layout. When you’re editing a page, go to the “Custom Design” tab. There you’ll see a form field called “Layout Update XML”. This is the key. Here’s where you add XML to first unset the breadcrumbs block and then add it back in but with your specific breadcrumbs. Here’s the code:
<reference name="root"> <action method="unsetChild"><alias>breadcrumbs</alias></action> </reference> <reference name="root"> <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"> <action method="addCrumb"> <crumbName>home</crumbName> <crumbInfo><label>Home</label><title>Go to Home Page</title><link>/</link></crumbInfo> </action> <action method="addCrumb"> <crumbName>foo</crumbName> <crumbInfo><label>Foo</label><title>Foo</title><link>/foo/</link></crumbInfo> </action> <action method="addCrumb"> <crumbName>cms_page</crumbName> <crumbInfo><label>Bar</label><title>Bar</title></crumbInfo> </action> </block> </reference>
The first reference tells Magento to call the unset action on the root block to remove the original breadcrumbs. The second reference tells Magento to add a new breadcrumbs block. Then within that block it tells Magento to add three new breadcrumbs, one for “home”, one for “foo”, and another for “bar”. crumbName is just a unique identifier. Under crumbInfo, label is the link text, title is the hover text, and link is the URL. You need to include the root forward slash. The trailing slash is optional, but to be consistent with Magento you should include it.
And that’s all there is to it. If you have a Magento site with lots of CMS subpages or pages that are deeply nested, then this method can get tedious. That’s why I said the optimal solution is to override the breadcrumbs module in core as a local modification. If you don’t have many CMS subpages and they’re only one-level deep, then this method is adequate.
Finally found the info I needed thanks to your great blog, thanks! ^^
Legend, thanks for sharing…
Man many thanks! you make my Day!
Thanks a lot. This is very helpful.
That’s exactly what I needed. Thank you.
Thanks for the helpful tip.
Cheers,
Ross.
Awesome tip and easy instructions. Had it working in a couple of minutes. I’m afraid of altering core files and all that, so I will put up with the tediousness! Thanks a ton.
Great. Very helpful. Was working in 5 minutes
Thank you so much for this great tip. I didn’t know that you could include slashes in the URL identifier — genius! Although with your neat breadcrumb work-around you can fake sub pages very well, I’m still unhappy with Magento CE lacking more CMS functionality (apparently you get a feature-rich solution in the Enterprise Edition). May it’s worth a try to integrate Magento with WordPress.