Thursday, July 13, 2017

Magento : add breadcrumbs to cms pages


Magento is an eCommerce application and it supports CMS features with few limitations. Magento displays, bread crumbs, which helps the user to know where they are and it displays the navigation path. Usually, the breadcrumb will be located below the header. But in Magento breadcrumb is available only in the catalog pages an not in the CMS pages or in the checkout pages.

Magento 2.X

  • On the Admin panel, Select Settings -> Stores -> Configuration.
  • In the panel on the left under General, select Web
  • Open the Default Pages section.
  • Change Show Breadcrumbs for CMS Pages to 'Yes'
  • When complete, click Save Config

Magento 1.X

`breadcrump.phtml` in `app/design/default/THEME/page` folder is responsible for displaying the breadcrumb. Add the following code to the breadcrumb.phtml file before the normal breadcrumb check to display the breadcrumb 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 activetrail', array('label' => $this->getLayout()->getBlock('head')->getTitle(), 'title' => $this->getLayout()->getBlock('head')->getTitle(), 'last' => 1));
	$crumbs = $breadcrumb->_crumbs;
}
 
The above code restricts the breadcrumb 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))

No comments :

Post a Comment