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

External database connection in Magento

Enabling Multi-part MIME Emails in Magento Tomislav Nikcevski
Tomislav Nikcevski

Enabling Multi-part MIME Emails in Magento

Pimcore Portlets Zoran Salamun
Zoran Salamun

Pimcore Portlets

Tell us about your project

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