Home » Magento20 February 2010

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.

From Mukesh Chapagain's Blog, post Magento: Easily add breadcrumbs to any page

php magento mukesh chapagain

Get New Post by Email

Find me on

Facebook Twitter Google+ LinkedIn RSS Feed
  • http://www.twozao.com Ela

    Hi ,

    I just added the custom breadcrumb to my checkout.xml under layout. And its coming in the checkout page as home/myaccount/ etc.

    But what i need is i want to add full category/sub category path of the product that is chosen by customer.

    Like

    Home/computers/processors/intel etc.. In the shopping cart page, product description page i have to add. Please tell me the solution. atleast i have to add this breadcrump in the product description page.

  • http://www.canvasprintsonline.com Canvas Art

    I could also do with knowing the answer to this, any ideas ?

  • Atif Kht

    Is there any way to get the breadcrumb on WordPress and PhpBB pages too ?? plz inform me via email when answer is posted over here.plz
    atif.kht@gmail.com

  • Amjath

     i created a new filed in the table. I called that in the admin side so that I can enter the value and its correctly saved.. that setion works perfectly. Now I need to call the custom filed to breadcrumb.phtml. I used $_crumbInfo['custom_field'] in the breadcrumbs.phtml and in breadcrumbs .php, inside function addCrumb, i added like this $this->_prepareArray($crumbInfo, array(‘label’, ‘title’, ‘link’, ‘first’, ‘last’, ‘readonly’, ‘custom_field’)); but is not working. Please help. Thanks in adv

  • Mohammad Adeel

    Hi Mukesh,

    I have added the code it works in the product list page but not in the product view page.
    Please give any solution.
    Thanks

  • Sunil830_talekar2007

    Thanks for sharing the knowledge

  • Elegant Rao

    how to make them dynamic , i mean i want to show breadcrumbs for my custom module.
    i doing my R&D on it. please do send me solution on my email
    elegant.rao@gmail.com
    thankyou

  • Janak

    Hi Mukesh

    I have added above code in custom module product listing page and its work fine…but not work in product view page. any solution…?

    Thank you…

  • Vishal

    Hi Mukesh,

    This code is not working in custom controller for frontend.
    We are getting following error:

    Fatal error: Call to a member function addCrumb() on a non-object in

    Can you please let me know the how to add breadcrumbs in controller??

    Thanks
    Vishal