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.
Best Answer
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
EDIT
This job is somewhat difficult to achieve. This is because, by default magento adds
home
breadcrumb andcategory
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 moduleRkt_Breadcrumbs
. First createconfig.xml
for your module.app\code\local\Rkt/Breadcrumbs/etc/config.xml
So our module just tells to magento that, it needs to rewrite the class
Mage_Catalog_Block_Breadcrumbs
with our classRkt_Breadcrumbs_Block_Breadcrumbs
. Now we can define our rewrite classFile :
app\code\local\Rkt/Breadcrumbs/Block/Breadcrumbs.php
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.It removes
Home
breadcrumbIt removes root category from the category array which is generated via the helper class
Mage_Catalog_Helper_Data::getBreadcrumbPath()
using the methodarray_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
Note : This will resolve issues in category page only.