Magento: Easily add breadcrumbs to any page

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.

Hope this helps. Thanks.