Try the Demo

Magento

eCommerce Software for Online Growth

Magento Forum

Our new hosted solution for small & emerging businesses
   
Page 1 of 2
Forcing Showing Breadcrumbs on Product Pages
 
Avera
Jr. Member
 
Total Posts:  10
Joined:  2009-03-07
 

Hi Guys,

So when Google visits a page in our Magento stores Google caches the page with no breadcrumbs.

This is because Google cahces the page as if it’s a direct hit to the product page.

For example, if you copy a product URL, close your browser, open browser and paste the URL back into the address bar there’s NO BREADCRUMBS.

I would like to find a way to show the breadcrumbs on a page such as this. Possibly a way of generating the breadcrumbs for ALL categories that the product is listed in, LIKE EBAY - Look at eBay’s breadcrumbs:

LCD Plasma Bracket on Ebay

Anyone any ideas how to do this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Avera
Jr. Member
 
Total Posts:  10
Joined:  2009-03-07
 

Homefully someone will be able to help with this issue as there are many threads asking for this:

http://www.magentocommerce.com/boards/viewthread/46509/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Avera
Jr. Member
 
Total Posts:  10
Joined:  2009-03-07
 

I have now been informed that the actual name for this functionality is called:

Related Category & Category Trail Hierarchy

I call it multiple category breadcrumbs.

But whatever it’s called, it’s an integral SEO requirement and even Google’s spider makes use of it.

I’m still on the case, 11 hours so far!

 
Magento Community Magento Community
Magento Community
Magento Community
 
MattBlalock
Jr. Member
 
Total Posts:  20
Joined:  2009-03-29
 

I am very interested in this feature as well. We we’re having problems with Google and Bing visitors getting confused and sort of “lost”. After doing a week of analysis using heatmaps, we realized that over half of the people who landed on a product page clicked the Home breadcrumb… and then left.

I believe they we’re looking for the category of the product to browse similar things, but of course, that isn’t there. We’ve researched all over for a solution, but have been unsuccessful. We posted a job to oDesk about it but not a single provider responded.

You have my support on this. Please keep us updated on it, even if you don’t find a solution.

Matt

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tutti
Member
 
Total Posts:  33
Joined:  2009-02-17
 

Me too! grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
nschneider
Jr. Member
 
Total Posts:  5
Joined:  2010-02-03
 

Is this resolved yet?!?!?! Freakin breadcrumbs are an older technology - but still a critical part of getting customers deeper into the catalog set and providing seo friendly links that can be crawled.  Anymore most customers are coming into a particular product page, so every chance to get them deeper in the website versus just hitting the “back” button should be used.  Anyone have a workaround or extension or something for this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikola99
Member
 
Total Posts:  47
Joined:  2010-04-09
 

Add this to top of breadcrumbs.phtml

<?php
if ($product Mage::registry('current_product')) {
    $categories 
$product->getCategoryCollection()->load();
    
    if(
$categories{
        
foreach ($categories as $category)
        
{
            
if($category{
                $category 
Mage::getModel('catalog/category')->load($category->getId());
                break;
            
}
        }
    }
    $lastCrumbName 
$product->getName();
    
$lastCategoryAdjust 0;
}
else {
    
if($category Mage::registry('current_category')) {
        $lastCrumbName 
$category->getName();
    
}
    $lastCategoryAdjust 
1;
}

if($category{
    
if($path $category->getPath()) {
        $path 
explode('/'$path);
        
$crumbs = array('home' => array('label' => 'Home',
                        
'title' => 'Home',
                        
'link' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB),
                        
'first' => true,
                        
'last' => false
        
));
        for(
$i 2$i count($path) - $lastCategoryAdjust$i++) {
            $cur_category 
Mage::getModel('catalog/category')->load($path[$i]);
            if(
$cur_category && $cur_category->getIsActive()) {
                $crumbs[
'category' $path[$i]] = array('label' =>  $cur_category->getName(),
                                  
'title' => $cur_category->getName(),
                                  
'link' => $cur_category->getUrl(),
                                  
'first' => false,
                                  
'last' => false
                
);
            
}
        }
        $crumbs[
'current'= array('label' => $lastCrumbName,
                       
'title' => '',
                       
'link' => '',
                       
'first' => false,
                       
'last' => true
        
);
    
}
}
?>

Note: I’ve tried and tried to create a module that overrides Mage_Catalog_Block_Breadcrumbs but Mage/Catalog/Block/Category/View.php and Mage/Catalog/Block/Product/View.php both create blocks using this class ( $this->getLayout()->createBlock(’catalog/breadcrumbs’); ) and apparently you cannot rewrite a block that is created through code. This is 1.4.1. But, this works, so I wasn’t about to go overriding both of those…

Edit FIxed a problem where the lays category wasn’t showing

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark Robinson
Member
 
Total Posts:  38
Joined:  2008-04-08
 

Thanks nikola99, that was exactly what I was looking for.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikola99
Member
 
Total Posts:  47
Joined:  2010-04-09
 

Turns out you can rewrite that block. I’ve created a module that does the work that used to be in the template.
Replace Namespace with your namespace.

app/etc/modules/<Namespace>_Categorytrail.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
[Namespace]_Categorytrail>
            <
active>true</active>
            <
codePool>local</codePool>
        </
[Namespace]_Categorytrail>
    </
modules>
</
config>

app/code/local/<Namespace>/Categorytrail/Block/Breadcrumbs.php

<?php
class <Namespace>_Categorytrail_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs
{
    
/**
     * Preparing layout
     *
     * @return Mage_Catalog_Block_Breadcrumbs
     */
    
protected function _prepareLayout()
    
{
        
if ($breadcrumbsBlock $this->getLayout()->getBlock('breadcrumbs')) {
            $title 
= array();
            
$path  Mage::helper('catalog')->getBreadcrumbPath();

            foreach (
$path as $name => $breadcrumb{
                $title[] 
$breadcrumb['label'];
            
}

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

            $lastCrumbClass 
'current';
            
// Determine what the last path name is: category or product. If product get it's parent category.
            // We're on a product page
            
if ($product Mage::registry('current_product')) {
                $categories 
$product->getCategoryCollection()->load();
                
                if(
$categories{
                    
foreach ($categories as $category)
                    
{
                        
if($category{
                            $category 
Mage::getModel('catalog/category')->load($category->getId());
                            break;
                        
}
                    }
                }
                $lastCrumbName 
$product->getName();
                
$lastCategoryAdjust 0;
                
$lastCrumbClass .= ' product';
            
}
            
else {
                
// We're on a category page
                
if($category Mage::registry('current_category')) {
                    $lastCrumbName 
$category->getName();
                
}
                $lastCategoryAdjust 
1;
            
}

            
if($category{
                
if($path $category->getPath()) {
                    $path 
explode('/'$path);
                    
$breadcrumbsBlock->addCrumb('home', array(
                        
'label'=>Mage::helper('catalog')->__('Home'),
                        
'title'=>Mage::helper('catalog')->__('Go to Home Page'),
                        
'link'=>Mage::getBaseUrl()
                    ));
                    
// Go up the path getting the categories. Skip the the two topmost categories (site root and Magento root)
                    // Also skip the last category (count - 1 is the last category) if we're on a category page now
                    
$j 0;
                    for(
$i 2$i count($path) - $lastCategoryAdjust$i++) {
                        $cur_category 
Mage::getModel('catalog/category')->load($path[$i]);
                        if(
$cur_category && $cur_category->getShowInMenu() && $cur_category->getIsActive()) {
                            $breadcrumbsBlock
->addCrumb('category' $j++, array(
                                
'label' => $cur_category->getName(),
                                
'title' => $cur_category->getName(),
                                
'link' => $cur_category->getUrl()
                            ));
                        
}
                    }
                    $breadcrumbsBlock
->addCrumb($lastCrumbClass, array(
                        
'label' => $lastCrumbName
                        
'title' => 'You are here'
                        
'link' => ''
                    
));
                
}
            }
        }
        
return $this;
    
}
}
Note: You can add extra functionallity on this line to exclude certain categories
if($cur_category && $cur_category->getIsActive()) {

app/code/local/<Namespace>/Categorytrail/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
[Namespace]_Categorytrail>
            <
version>1.0</version>
        </
[Namespace]_Categorytrail>
    </
modules>
    <global>
        <
blocks>
            <
categorytrail>
                <class><
Namespace>_Categorytrail_Block</class>
            </
categorytrail>
            <
catalog>
                <
rewrite>
                    <
breadcrumbs><Namespace>_Categorytrail_Block_Breadcrumbs</breadcrumbs>
                </
rewrite>
            </
catalog>
        </
blocks>
    </global>
</
config>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paul Whipp
Member
 
Total Posts:  48
Joined:  2009-03-23
 

Thanks for providing this code Nikola99! Even though it does not work for me, I could not have done this alternative solution without your solution. I hope my solution will prove more general.

Some background:

A product may exist in more than one category.

If a product is directly referenced by URL, the breadcrumb trail can’t show a category path because there is no unique path of categories to the product. However, from the customer\’s perspective, any path is better than none so its better to just get the first appropriate path rather than show no path.

My solution just ensures that if a product is known then the current category will be set to the first category found that the product is in if there is no category currently available. This yields a category for the breadcrumb trail if we’re looking at a product (on the assumption that all products are in at least one category).

To do this I have specialized the default catalog helper to return a product category in cases where there is no current category but there is a product (from which a ‘reasonable’ category may be selected.

Here is the solution (thanks again Nikola99 for making this process nice and clear):

Enable your module as per Nikola99\’s instructions. We\’re gonig to extend the Data.php helper in catalog with one function so create
app/code/local/[yourtheme]/Catalog/Helper/Data.php

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category    Mage
 * @package     Mage_Catalog
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Catalog data helper
 *
 * @category   Mycomp
 * @package    Mycomp_Catalog
 * @author     paul.whipp@gmail.com (www.paulwhippconsulting.com.au)
 */
class Mycomp_Catalog_Helper_Data extends Mage_Catalog_Helper_Data {

    
/**
     * Return current category object
     *
     * @return Mage_Catalog_Model_Category|null
     */
    
public function getCategory()
    
{
        
//
        // If there is a current category then return it (currently default behaviour)
        
$current_category Mage::registry('current_category');
        if (
$current_category) return $current_category;
        
//
        // If there is a current product use that to provide a
        // current category
        
$current_product $this->getProduct();
        if (
$current_product){
            $categories 
$current_product->getCategoryCollection()->load();
            foreach (
$categories as $category{
                
if($category{
                    
return Mage::getModel('catalog/category')->load($category->getId());
                
}
            }
        }
        
//
        // Default behaviour
        
return parent::getCategory();
    
}
}
?>

Now extend the active module’s config.xml to include the rewrite for the standard catalog helper class:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <global>
        ...
        <
helpers>
            <
catalog>
                <
rewrite>
                    <
data>Mycomp_Catalog_Helper_Data</data>
                </
rewrite>
            </
catalog>
        </
helpers>
  </global>
</
config>

All done. This has the benefit of simplicity and should work in all cases.

 Signature 

Regards,
Paul Whipp

Joomla, Magento, PHP and MySQL web application developer

 
Magento Community Magento Community
Magento Community
Magento Community
 
nimonogi
Jr. Member
 
Total Posts:  28
Joined:  2008-11-08
 

breadcrumbs.phtml hack works great! Thanks for sharing!

You can replace:

$crumbs = array('home' => array('label' => 'Home',
with:
$crumbs = array('home' => array('label' => $this->__('Home'),
to get “Home” from your language file.

 Signature 

European Web Hosting by Brontobytes

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bruno Morejon
Sr. Member
 
Avatar
Total Posts:  83
Joined:  2009-06-05
 

Is this corrected in newer versions?

 Signature 

Bruno Morejon
Diretor de Tecnologia
http://www.zinx.com.br

 
Magento Community Magento Community
Magento Community
Magento Community
 
spectrumaudio
Member
 
Total Posts:  32
Joined:  2008-07-22
 

Works great, Thank you so much!

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  322
Joined:  2008-11-26
Dortmund, Germany
 

nikola, Paul: Awesome work!

 
Magento Community Magento Community
Magento Community
Magento Community
 
webpixie
Jr. Member
 
Total Posts:  28
Joined:  2009-07-14
 

I could not get the extension to work, is it working for 1.5?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Metzed
Member
 
Total Posts:  32
Joined:  2010-08-11
 

I also can’t get this to work in 1.5. I can add Nikola\’s original code to breadcrumbs.phtml and that works, but I can’t get Nikola\’s module to work. Has anyone got this module to work in 1.5? From what I can see, Nikola\’s instructions are quite clear, so there’s not a lot that could go wrong, which makes me wonder if this works in 1.5. Can anyone help?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2
 
© Copyright 2012 Magento Inc.
Privacy Policy|Terms of Service
Magento Community Count
701238 users|916 users currently online|497183 forum posts