Skip to main content
added 18 characters in body
Source Link
Rajeev K Tomy
  • 17.3k
  • 6
  • 63
  • 103
<?php
class Rkt_Breadcrumbs_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs
{
    protected function _prepareLayout()
    {
        if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
            
            $title = array();
            $path  = array_shift(Mage::helper('catalog')->getBreadcrumbPath());
            array_shift($path);
            foreach ($path as $name => $breadcrumb) {
                $breadcrumbsBlock->addCrumb($name, $breadcrumb);
                $title[] = $breadcrumb['label'];
            }

            if ($headBlock = $this->getLayout()->getBlock('head')) {
                $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
            }
        }
        return parent::_prepareLayout();
    }
}
<?php
class Rkt_Breadcrumbs_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs
{
    protected function _prepareLayout()
    {
        if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
            
            $title = array();
            $path  = array_shift(Mage::helper('catalog')->getBreadcrumbPath());

            foreach ($path as $name => $breadcrumb) {
                $breadcrumbsBlock->addCrumb($name, $breadcrumb);
                $title[] = $breadcrumb['label'];
            }

            if ($headBlock = $this->getLayout()->getBlock('head')) {
                $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
            }
        }
        return parent::_prepareLayout();
    }
}
<?php
class Rkt_Breadcrumbs_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs
{
    protected function _prepareLayout()
    {
        if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
            
            $title = array();
            $path  = Mage::helper('catalog')->getBreadcrumbPath();
            array_shift($path);
            foreach ($path as $name => $breadcrumb) {
                $breadcrumbsBlock->addCrumb($name, $breadcrumb);
                $title[] = $breadcrumb['label'];
            }

            if ($headBlock = $this->getLayout()->getBlock('head')) {
                $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
            }
        }
        return parent::_prepareLayout();
    }
}
added 2718 characters in body
Source Link
Rajeev K Tomy
  • 17.3k
  • 6
  • 63
  • 103

EDIT

This job is somewhat difficult to achieve. This is because, by default magento adds home breadcrumb and category breadcrumbs from two different files. So basically you cannot avoid a rewrite atleast. So make your work more clean, you need to create a module. I am going to call this module Rkt_Breadcrumbs. First create config.xml for your module.

app\code\local\Rkt/Breadcrumbs/etc/config.xml

<config>
    <modules>
        <Rkt_Breadcrumbs>
            <version>1.0.0</version>
        </Rkt_Breadcrumbs>
    </modules>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <breadcrumbs>Rkt_Breadcrumbs_Block_Breadcrumbs</breadcrumbs>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

So our module just tells to magento that, it needs to rewrite the class Mage_Catalog_Block_Breadcrumbs with our class Rkt_Breadcrumbs_Block_Breadcrumbs. Now we can define our rewrite class

File : app\code\local\Rkt/Breadcrumbs/Block/Breadcrumbs.php

<?php
class Rkt_Breadcrumbs_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs
{
    protected function _prepareLayout()
    {
        if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
            
            $title = array();
            $path  = array_shift(Mage::helper('catalog')->getBreadcrumbPath());

            foreach ($path as $name => $breadcrumb) {
                $breadcrumbsBlock->addCrumb($name, $breadcrumb);
                $title[] = $breadcrumb['label'];
            }

            if ($headBlock = $this->getLayout()->getBlock('head')) {
                $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
            }
        }
        return parent::_prepareLayout();
    }
}

Here we are rewriting the method _prepareLayout(). Here if you compare the two methods, you can see that our new _prepareLayout() method do two jobs.

  1. It removes Home breadcrumb

  2. It removes root category from the category array which is generated via the helper class Mage_Catalog_Helper_Data::getBreadcrumbPath() using the method array_shift. That's it. You are done. Dont forget to add the activation file of the module. It looks like this.

File : app\etc\modules/Rkt_Breadcrumbs.xml

<config>
    <modules>
        <Rkt_Breadcrumbs>
            <active>true</active>
            <codePool>local</codePool>
            <depends> 
                <Mage_Catalog/>
            </depends>
        </Rkt_Breadcrumbs>
    </modules>
</config>

Note : This will resolve issues in category page only.

EDIT

This job is somewhat difficult to achieve. This is because, by default magento adds home breadcrumb and category breadcrumbs from two different files. So basically you cannot avoid a rewrite atleast. So make your work more clean, you need to create a module. I am going to call this module Rkt_Breadcrumbs. First create config.xml for your module.

app\code\local\Rkt/Breadcrumbs/etc/config.xml

<config>
    <modules>
        <Rkt_Breadcrumbs>
            <version>1.0.0</version>
        </Rkt_Breadcrumbs>
    </modules>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <breadcrumbs>Rkt_Breadcrumbs_Block_Breadcrumbs</breadcrumbs>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

So our module just tells to magento that, it needs to rewrite the class Mage_Catalog_Block_Breadcrumbs with our class Rkt_Breadcrumbs_Block_Breadcrumbs. Now we can define our rewrite class

File : app\code\local\Rkt/Breadcrumbs/Block/Breadcrumbs.php

<?php
class Rkt_Breadcrumbs_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs
{
    protected function _prepareLayout()
    {
        if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
            
            $title = array();
            $path  = array_shift(Mage::helper('catalog')->getBreadcrumbPath());

            foreach ($path as $name => $breadcrumb) {
                $breadcrumbsBlock->addCrumb($name, $breadcrumb);
                $title[] = $breadcrumb['label'];
            }

            if ($headBlock = $this->getLayout()->getBlock('head')) {
                $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
            }
        }
        return parent::_prepareLayout();
    }
}

Here we are rewriting the method _prepareLayout(). Here if you compare the two methods, you can see that our new _prepareLayout() method do two jobs.

  1. It removes Home breadcrumb

  2. It removes root category from the category array which is generated via the helper class Mage_Catalog_Helper_Data::getBreadcrumbPath() using the method array_shift. That's it. You are done. Dont forget to add the activation file of the module. It looks like this.

File : app\etc\modules/Rkt_Breadcrumbs.xml

<config>
    <modules>
        <Rkt_Breadcrumbs>
            <active>true</active>
            <codePool>local</codePool>
            <depends> 
                <Mage_Catalog/>
            </depends>
        </Rkt_Breadcrumbs>
    </modules>
</config>

Note : This will resolve issues in category page only.

Source Link
Rajeev K Tomy
  • 17.3k
  • 6
  • 63
  • 103

if you just want to remove breadcrumbs from home page and category pages, then you can do it easily by a layout update. Use local.xml file to do this.

File : app\design\frontend\<your_package>\<your_theme>\layout\local.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="root">
           <remove name="breadcrumbs"/>
        </reference>
    </default>

    <catalog_category_default>
        <reference name="root">
           <remove name="breadcrumbs"/>
        </reference>
    </catalog_category_default>

    <catalog_category_layered>
        <reference name="root">
           <remove name="breadcrumbs"/>
        </reference>
    </catalog_category_layered>
 </layout>