Add breadcrumbs in Magento to pages that miss them

Add breadcrumbs in Magento to pages that miss them

Here is one solution on how to add breadcrumbs to pages in Magento that by default do not have breadcrumbs. Recently we had a client that requested a basic breadcrumb to be shown on pages that Magento does not serve breadcrumbs.

<?php
/**
*
* CUSTOM BREADCRUMBS
*
* Adds url breadcrumbs for pages that do not have breadcrumbs by default
*
*/
 
?>
<?php if(is_null($crumbs)): ?>
<?php
 
/**
* NOTE
* On some servers use ->getServer('PATH_INFO')
* and on some ->getServer('ORIG_PATH_INFO')
*/
 
$urlRequest = Mage::app()->getFrontController()->getRequest();
$urlPart = $urlRequest->getServer('ORIG_PATH_INFO');
 
if(is_null($urlPart))
{
$urlPart = $urlRequest->getServer('PATH_INFO');
}
 
$urlPart = substr($urlPart, 1 );
$currentUrl = $this->getUrl($urlPart);
 
//$controllerName = Mage::app()->getFrontController()->getRequest()->getControllerName();
//$controllerName = ucfirst($controllerName);
 
$controllerName = str_replace("/", " ", $urlPart);
$controllerName = str_replace("_", " ", $controllerName);
$controllerName = str_replace("-", " ", $controllerName);
$controllerName = ucfirst($controllerName);
 
?>
<span class="breadcrumbs">
<strong class="float"><?php echo $this->__("You're currently on: ") ?></strong>
<ul class="breadcrumbs">
<li class="home">
<a title="<?php echo $this->__('Go to Home Page') ?>" href="<?php echo $this->getUrl() ?>"><?php echo $this->__('Home') ?></a>
</li>
<li> / </li>
<li class="<?php echo strtolower($controllerName) ?>">
<strong><?php echo $this->__($controllerName) ?></strong>
</li>
</ul>
</span>
<?php endif; /* END OF CUSTOM BREADCRUMBS */ ?>

You made it all the way down here so you must have enjoyed this post! You may also like:

External database connection in Magento Damir Serfezi
Damir Serfezi, | 4

External database connection in Magento

Enabling Multi-part MIME Emails in Magento Tomislav Nikcevski
Tomislav Nikcevski, | 3

Enabling Multi-part MIME Emails in Magento

Pimcore Portlets Zoran Salamun
Zoran Salamun, | 0

Pimcore Portlets

10 comments

  1. Found a solution !
    If you get errors on product page, add this condition in the ‘else’ statement :

    if($this->getLayout()->getBlock(‘head’)):

    endif;

  2. Hi,
    I tried ali’s solution to display breadcrumbs on pages where it’s not display by default (cart for example). It works fine. But it breaks the Ajax add to cart function on product page (Cannot read property “innerHTML” of undefined).
    When i look in php_error.log, i’ve got :

    PHP Fatal error: Call to a member function getTitle() on a non-object in F:\www\axente\server\app\design\frontend\axente\default\template\page\html\breadcrumbs.phtml on line 55

    any idea ?

  3. Hello Jonathan!

    The breadcrumbs work fine on the other pages just not the sale and the contact form.
    i am using the magento 1.6 verson.
    i dont understand wt i do at this situation.

  4. The app/design/frontend/YourPackage/Yourthem/template/page/html/breadcrumb.phtml is good place to customize or play with the breadcrumb, if breadcrumb is null and you want to keep the breadcrumb consistancy than the else portion with the following code snap will be worth to avoid that tidy xml additions.

    <?php else : ?>
    $homelink=Mage::getBaseUrl() ; 
    $title=$this->getLayout()->getBlock('head')->getTitle(); 
    ?>
    <li><a title="<?php echo $this->__('Go to Home Page') ?>" href="<?php echo $homelink; ?>"><?php echo $this->__('Home') ?></a></li>
    <li><a href="[removed];" class="active"><?php echo $this->__($title); ?></a></li> 
    <?php endif; ?>
  5. Feel kind of dumb but I figured out the issue, the old programmer set the display to none in the css.

    Thank you very much for working my brain enough to figure it out!

  6. In that case, is it possible you can post your complete code someplace such as Pastebin.com or Stack Overflow so we can take a look at it? If you’re evoking getChildHtml(‘breadcrumbs’), you need to do so in the template file that is the parent of the breadcrumbs template (usually something like page/3columns.phtml). Also, you’ll need to ensure that the getBreadcrumbPath method is returning the appropriate information and is a method of the Mage_Catalog_Helper_Abstract class — you can do this by checking the output of get_class() on $this.

  7. Hello Jonathan!

    Thank you for the response.

    I am not getting any errors that I can find.

    I am using 1.4 and it is a theme from another designer that I am not in contact with.

    The breadcrumbs work fine on the other pages just not the categories page.

    I am very confused.

  8. Hi Matt, what version of Magento might you be running? Do you get any errors? (For errors, be sure to check all three places: your server log, and your Exception and System log files [usually at MAGE_ROOT/var/log/ where MAGE_ROOT is the root directory of your Magento installation].)

  9. Hello Jonathan,

    I have done this then added:

    getChildHtml(‘breadcrumbs’) ?>

    To one of my pages but they still do not show up?

    Any tips?

  10. Not certain what version of Magento this article was originally written for, but an easy way to enable breadcrumbs is by adding a breadcrumbs.phtml file to your theme/template/page/html directory (essentially a theme-specific override of design/frontend/base/default/page/html/breadcrumbs.phtml) and add the following line to the beginning of the breadcrumbs.phtml file:

    <?php $this->getBreadcrumbPath(); ?>

    This evokes the getBreadcrumbPath method in code/core/Mage/Catalog/Helper/Data.php, which generates a breadcrumb and assigns it to the protected $_crumbs variable (which the breadcrumbs.phtml file inherits from: see code/core/Mage/Catalog/Block/Breadcrumbs.php).

    This is in Magento 1.5.0.1. Hope this helps someone!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.