Home » Magento

Magento: Easily add breadcrumbs to any page

20 February 2010 11,930 views Popularity: 24% Share/Bookmark

email

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.

Related posts:

  1. Magento: Create CMS Page & Static Block programmatically
  2. Magento: Set/Change page layout, title tag, meta keywords and description
  3. How to show child page (sub page) list in parent page in wordpress?
  4. jQuery: Grey out background and preview image as popup
  5. Magento: Get current Url of the page
  6. Magento: How to change default page layout?
  7. Magento: Show Currency Selector in header
  8. Magento: Access denied in admin of custom module
  9. Magento: Solution to “Error: 404 Not Found” in Admin Login Page
  10. Magento: Redirect Customer to Login page if not logged in
  • 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