1

I am trying to remove the breadcrumb link home.

Also all categories just so it isnt to much writing as a lot of our categories names are rather long.

For example

So instead of it saying

HOME->ALL CATEGORIES->TOPS->POLO-TOPS

I want it to say

TOP->POLO-TOPS

I have tried to just add this if statement to the breadcrumbs.phtml

<?php if ($_crumbName != 'home' ){?>

Which seems correct but it isnt doing anything so i dont know if i have this in the wrong place or am just going about this wrong. I have entered my full code below.

  $crumbsLevels = $this->getAllBreadcrumbs();
?>
<?php if($crumbsLevels && is_array($crumbsLevels)): ?>
<div class="breadcrumbs">
    <?php foreach ($crumbsLevels as $crumbs): ?>
    <?php if ($crumbName != home ){?>
    <ul>
        <?php foreach($crumbs as $_crumb): ?>
        <li <?php if ((!empty($_crumb['category_id']) || count($crumbs) >4) && !$_crumb['last']) { ?>typeof="v:Breadcrumb"<?php } ?><?php if (!empty($_crumb['hidden'])) { echo 'style="visibility: hidden;"'; } ?>>
        <?php if(!empty($_crumb['link'])): ?>
            <a href="<?php echo $_crumb['link'] ?>" title="<?php echo $this->htmlEscape($_crumb['title']) ?>" <?php if (!empty($_crumb['category_id'])) { ?>rel="v:url" property="v:title"<?php } ?>><?php echo $this->htmlEscape($_crumb['title']) ?></a>
        <?php elseif($_crumb['last']): ?>
            <strong><?php echo $this->htmlEscape($_crumb['title']) ?></strong>
        <?php else: ?>
            <?php echo $this->htmlEscape($_crumb['title']) ?>
        <?php endif; ?>
        <?php if(!$_crumb['last']): ?>
            <span>  </span>
        <?php endif; ?>
        </li>
        <?php endforeach; ?>
    </ul>
    <?php }?>
    <?php endforeach; ?>
</div>
<?php endif; ?>

I know i didnt mention the all categories but wanted to egt the Home link done first and i assume it will just be the same but using the category ID or the name 'All Categories'?

If someone could let me know where i am going wrong or what is should be writing in that would be great thank you.

2
  • Your code worked for me, even without quoting home in the if statement, so if it wasn't working for you you probably need to check your caches, and that you're actually using the template file that you're including.
    – Richard
    Oct 28 '14 at 11:24
  • @Richard you are completely right I was looking in the wrong folder. and the folder in the file i am using looks nothign liek the one above so i will edit my question. Thanks for pointing that out
    – Adam Allen
    Oct 28 '14 at 12:01
1

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>

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  = 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();
    }
}

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.

13
  • i think you misunderstood, i dont want to remove them from them actual pages i want to remove them as links when you are on any page. So instead of it saying HOME->ALL CATEGORIES->TOPS->POLO-TOPS. I want it to say TOP->POLO-TOPS. I will make that clear in my question
    – Adam Allen
    Oct 28 '14 at 11:23
  • is POLO-TOPS product or category?
    – Amit Bera
    Oct 28 '14 at 11:25
  • you need this feature only for categories ? what about homepage ? what about other pages ? Oct 28 '14 at 11:26
  • POLO-TOPS is a category but even on product pages i dont want 'HOME' or 'ALL CATEGORIES' i just dont want Them to show on any pages
    – Adam Allen
    Oct 28 '14 at 11:38
  • ALL CATEGORIES is your root category ? Oct 28 '14 at 11:51
2

Remove specific crumb from breadcrumbs

1. Extend class Mage_Page_Block_Html_Breadcrumbs and create method removeCrumb()

app/etc/modules/Namespace_Module.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Module>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Page />
            </depends>
        </Namespace_Module>
    </modules>
</config> 

app/code/local/Namespace/Module/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Module>
            <version>0.0.1</version>
        </Namespace_Module>
    </modules>
    <global>
        <blocks>
            <namespacemodule>
                <class>Namespace_Module_Block</class>
            </namespacemodule>
            <page>
                <rewrite>
                     <html_breadcrumbs>Namespace_Module_Block_Page_Html_Breadcrumbs</html_breadcrumbs>
                </rewrite>
            </page>
        </blocks>
    </global>
</config> 

app/code/local/Namespace/Module/Block/Page/Html/Breadcrumbs.php

class Namespace_Module_Block_Page_Html_Breadcrumbs extends Mage_Page_Block_Html_Breadcrumbs {

    function removeCrumb($crumbName) {
        if ((!isset($this->_crumbs[$crumbName])) || (!$this->_crumbs[$crumbName]['readonly'])) {
            unset($this->_crumbs[$crumbName]);
        }
        return $this;
    }

}

2. Call this method from Mage/Catalog/Block/Product/view.php to local/Catalog/Block/Product/view.php after line

$this->getLayout()->createBlock(‘catalog/breadcrumbs’);

The string which you should pass through method removeCrumb is nothing more than ‘category’+category_id.

$this->getLayout()->createBlock('catalog/breadcrumbs'); 
$this->getLayout()->getBlock('breadcrumbs')->removeCrumb('home');
$this->getLayout()->getBlock('breadcrumbs')->removeCrumb('allcategory'); // You

More info

You can also remove breadcrumbs via your local.xml (preferred method) as you're able to use specific handles. The below example attaches to default which is on every page, but you can be more specific than this.

<default>
    <reference name="breadcrumbs">
        <action method="removeCrumb"><crumbName>home</crumbName></action>
    </reference>
</default>
1
  • What is ` || (!$this->_crumbs[$crumbName]['readonly'])` for?
    – sv3n
    Oct 16 '17 at 18:04
0

Im sure all these awnsers will work but i found a much easier method.

First create a variable which take in the breadcrumb

<?php $test = $crumbs?>

Then var_dump it to check what your Name is being called mine was "title"

Create a variable which takes in the crumbs title

<?php $name = $_crumb ['title'];?>

Then create IF statements that check that the title is not the titles you do not want.

<li <?php if ($name != 'Home' ){?>
<?php if ($name != 'All Categories' ){?>
1
  • Though it solves your problem, this solution is not at all a global solution for the problem that is described in your own question. and is not the right way to do it. If you need to do it in clean way, you need to follow the "module" way. :-) Anyway, please accept any of the answer (including yours) that helped you to resolve the issue. Please dont leave your question as it is :-) Oct 29 '14 at 13:01
0

Magento is managed it Category and product page breadcrumbs using Mage_Catalog_Helper_Data class function getBreadcrumbPath function here magento check Category and product object is exits in current category depends on this magento create breadcrumbs.

Note:

You need to write this class.

First depend on current category Path create an array which containing a hierarchical category tree ids then

$pathInStore = $category->getPathInStore();
$pathIds = array_reverse(explode(',', $pathInStore));

then create breadcrumbs using below code

$categories = $category->getParentCategories();

// add category path breadcrumb
foreach ($pathIds as $categoryId) {
    if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) {
        $path['category'.$categoryId] = array(
            'label' => $categories[$categoryId]->getName(),
            'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : ''
        );
    }
}

HOME->ALL CATEGORIES->TOPS->POLO-TOPS.

As you want to 

TOPS->POLO-TOPS. that means you want only last category then

you need modify code if it category page

$pathInStore = $category->getPathInStore();
$pathIds = array_reverse(explode(',', $pathInStore));

$categories = $category->getParentCategories();

// add category path breadcrumb
// put All Category id in loop to remove All category from crumns
foreach ($pathIds as $categoryId) {
    $categoryId= end($pathIds);
    if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) {
        $path['category'.$categoryId] = array(
            'label' => $categories[$categoryId]->getName(),
            'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : ''
        );
    }
}

And for remove Home link from catalog page you need rewrite class

Mage_Catalog_Block_Breadcrumbs and and remove

$breadcrumbsBlock->addCrumb('home', array(
    'label'=>Mage::helper('catalog')->__('Home'),
    'title'=>Mage::helper('catalog')->__('Go to Home Page'),
    'link'=>Mage::getBaseUrl()
));

from rewrite code

3
  • you are in the right path. But editing core code is a big NO NO :-) Oct 28 '14 at 11:52
  • I dont want HOME -> POLO TOPS. I DONT want HOME there at all. or ALL CATEGORIES
    – Adam Allen
    Oct 28 '14 at 11:58
  • @AmitBera: we can avoid two rewrites like in my method. Please go through it friend Oct 28 '14 at 12:36
0

I'd prefer ravi patels solution, because this i what Magento just missed and should be in core. If you can add elements via layout update, you should also be able to remove them.

Btw ... i think there is something wrong with !isset($this->_crumbs[$crumbName])) || .... Without readonly check ...

public function removeCrumb($crumbName)
{
    if (isset($this->_crumbs[$crumbName])) {
        unset($this->_crumbs[$crumbName]);
    }
}

Optional #1

If you alread rewrite Mage_Page_Block_Html_Breadcrumbs block, you can fix addCrumb($crumbName, $crumbInfo, $after = false) method, where 3rd parameter $after is not used. Just replace ...

$this->_crumbs[$crumbName] = $crumbInfo;

with

if ($after && isset($this->_crumbs[$after])) {
    $offset = array_search($after, array_keys($this->_crumbs)) + 1;
    $this->_crumbs = array_slice($this->_crumbs, 0, $offset, true) + array($crumbName => $crumbInfo) + array_slice($this->_crumbs, $offset, null, true);
} else {
    $this->_crumbs[$crumbName] = $crumbInfo;
}

Optional #2

If you want to a crumbs before another, add this ...

public function addCrumbBefore($crumbName, $crumbInfo, $before = false)
{
    if ($before && isset($this->_crumbs[$before])) {
        $keys = array_keys($this->_crumbs);
        $offset = array_search($before, $keys);
        # add before first
        if (!$offset) {
            $this->_prepareArray($crumbInfo, array('label', 'title', 'link', 'first', 'last', 'readonly'));
            $this->_crumbs = array($crumbName => $crumbInfo) + $this->_crumbs;
        } else {
            $this->addCrumb($crumbName, $crumbInfo, $keys[$offset-1]);
        }
    } else {
        $this->addCrumb($crumbName, $crumbInfo);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.