How to add breadcrumbs to a specific page in Magento
Sometimes you will find out that there are some pages in Magento with no breadcrumbs enabled by default. In order to add Breadcrumbs, for example, on the checkout page, open checkout.xml file stored in ‘layout’ folder of the current theme, and find there ‘checkout_onepage_index’ block. Then add to the block this code:
<reference name="breadcrumbs"> <action method="addCrumb"> <crumbName>Home</crumbName> <crumbInfo> <label>Home</label> <title>Home</title> <link>/home</link> </crumbInfo> </action> <action method="addCrumb"> <crumbName>Cart</crumbName> <crumbInfo> <label>Cart</label> <title>Cart</title> </crumbInfo> </action> </reference>
The above described example illustrates how to show breadcrumbs with the help of xml, but it is possible to do it directly in the code of the phtml files. With the help of the line (see the example below) it is possible to enable breadcrumbs and show it on a certain page:
echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();
This example describes a simple method how to add custom breadcrumbs:
// get breadcrumbs block $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); // add first item with link $breadcrumbs->addCrumb( 'home', array( 'label'=>$this->__('Home'), 'title'=>$this->__('Home'), 'link'=>Mage::getBaseUrl() ) ); // add second item without link $breadcrumbs->addCrumb( 'brands', array( 'label'=>$this->__('Brands'), 'title'=>$this->__('Brands') ) ); echo $breadcrumbs->toHtml();
That’s it…:)
Cool…. it works perfectly.