Adding Breadcrump to cms pages in Magento

 

Magento is a eCommerce application and it supports CMS features but it has few limitation. Magento displays breadcrumps, which helps the user to know where they are and it displays the navigation path. But this breadcrump is available only in the catalog pages an not in the cms pages or in the checkout pages. 

'breadcrump.phtml' in 'app/design/default/yourtemplate/page' folder is responsible for displaying the breadcrump. Add the following code to the breadcrump.phtml file before the normal breadcrump check  to display the breadcrump in the cms, shopping cart and checkout pages.

if ((!$crumbs || !is_array($crumbs)) && $this->getUrl('') != $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))) {
 
    $breadcrumb = $this->getLayout()->getBlock('breadcrumbs');
 
    $breadcrumb->addCrumb('home', array('label' => Mage::helper('cms')->__('Home'), 'title' => Mage::helper('cms')->__('Home Page'), 'link' => Mage::getBaseUrl()));
 
    $breadcrumb->addCrumb('my_account activeBreadcrumb', array('label' => $this->getLayout()->getBlock('head')->getTitle(), 'title' => $this->getLayout()->getBlock('head')->getTitle(), 'last' => 1));
 
    $crumbs = $breadcrumb->_crumbs;
 
}

The above code restricts the breadcrump to be displayed from the home page, if you want that to be shown also in the home page, then remove the following condition from the first line of the above code.

$this->getUrl('') != $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))

This code check whether the current page is home page or not. Since Home is a CMS page in Magento, normally breadcrumps won't be displayed. 

  • Hashid Hameed

    thanks for the post. helped me!