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