Technology + People + Process

Adding Breadcrumbs to Custom Pages in Magento

Adding Breadcrumbs to Custom Pages in Magento

Breadcrumbs are very useful for user navigation. Breadcrumbs for product page, category page, etc. are created by default Magento code.The following code will show breadcrumbs created by Magento. You can print the following code anywhere in php or phtml files.

echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();

You can create you own breadcrumbs as well. Like, you may need to create breadcrumbs if you have your own custom built module. I will show you here, how you can do it.

It’s simple and easy. At first, you will define the breadcrumbs block. Then, you will add label, title and link to your breadcrumbs. The addCrumb Magento function is used in this case.

******************************************************************************

$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');

$breadcrumbs->addCrumb('home', array('label'=>Mage::helper('cms')->__('Home'), 'title'=>Mage::helper('cms')->__('Home Page'), 'link'=>Mage::getBaseUrl()));

$breadcrumbs->addCrumb('country', array('label'=>'Country', 'title'=>'All Countries', 'link'=>'http:// example.com/magento/moduleName/country'));

$breadcrumbs->addCrumb('manufacturer', array('label'=>'State', 'title'=>'States'));

echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();

******************************************************************************

The label, title and link can be changed according to your need and requirement.

You can use another method to create breadcrumbs to your custom page by using only  xml file.

You need to declare the breadcrumbs reference block in corresponding handler of an xml file,for example see the following code.

******************************************************************************

<reference name="breadcrumbs">

                <action method="addCrumb">

                        <name>home</name>

                        <params><label>Home</label><title>Home</title><link>/</link></params>

                </action>

                <action method="addCrumb">

                        <name>authors</name>

                        <params><label>Authors</label><title>Authors</title><link>/index.php/managingusers/index/authorlist</link></params>

                </action>

                <action method="addCrumb">

                        <name>searchlist</name>

                        <params><label>Search List</label><title>SearchList</title><link /></params>

                </action>

          </reference>

******************************************************************************


Request for Quote

Drop us a line and we'll get in touch with you as quick as we can