1

I am trying to move the breadcrumbs to inside a category page, and Ive been struggling. I have been looking at the following resources, but they have not helped:

I have added the following to remove the breadcrumbs from root and then add them as a child of category.products. Like so:

<catalog_category_layered translate="label">
    <reference name="root">
        <remove name="breadcrumbs"/>
    </reference>
    <reference name="category.products">
        <block type="page/html_breadcrumbs" name="onlybreadcrumbs" as="onlybreadcrumbs" template="page/html/breadcrumbs.phtml"/>
    </reference>
</catalog_category_layered>

This is at the top of catalog/category/view.phtml I am adding the breadcrumbs file with this:

<?php echo $this->getLayout()->getBlock('onlybreadcrumbs')->toHtml(); ?>

At the top of page/html/breadcrumbs.phtml I have this:

<pre>Crumbs:<?php var_dump($crumbs); ?></pre>

The output at the top of a category pages is this:

Crumbs:NULL

My problem here is that after moving the breadcrumbs into the category view file, the $crumbs variable is NULL, and as a result none of the breadcrumbs appear.


In the end I used code from this page to get around the problem: http://awebtech.blogspot.co.uk/2011/04/magento-add-breadcrumbs-in-pages-where.html

However this solution is basically to just rebuild the breadcrumbs from scratch, and it feels like a bit of a hack.

Can someone explain to me, after moving the breadcrumbs into another file, why $crumbs is now NULL - and most importantly, how to fix this issue properly.

1

Just came across the same issue. Following http://awebtech.blogspot.co.uk/2011/04/magento-add-breadcrumbs-in-pages-where.html I made some adjustments, added (category) levels and links.

1) Add this code at the end of breadcrumbs.phtml

<?php if(!$crumbs): ?>
<?php
$urlRequest = Mage::app()->getFrontController()->getRequest();

$urlPart =  $urlRequest->getOriginalPathInfo();
if(is_null($urlPart))
{
    $urlPart = $urlRequest->getPathInfo();
}

$urlPart = substr($urlPart, 1 );
$currentUrl = $this->getUrl($urlPart);


$urlChunks = explode("/",$urlPart);

$lastlink = "";
$i = 0;
foreach($urlChunks as $urlChunk)
{
    $crumbLabel = ucfirst(str_replace(["-","_",".html"], " ", $urlChunk));
    $crumbs[$i]['label'] = $crumbLabel;
    $crumbs[$i]['link'] = $this->getUrl().($lastlink ? $lastlink."/" : "").str_replace(".html","",$urlChunk).".html";
    $lastlink = $urlChunk;
    $i++;
    if($i == count($urlChunks))
    {
        $crumbs[$i -1]['last'] = true;
        $crumbs[$i -1]['link'] = "";
    }

}
?>

This will create breadcrumbs array based on the current url.

2) Copy and paste the html code that prints the breadcrumb (<div class="breadcrumbs">...</div>) which should be the first thing in this .phtml.

| improve this answer | |
0

Follow this

<catalog_category_layered translate="label">
        <reference name="root">
            <action method="unsetChild">
                <name>breadcrumbs</name>
            </action>
        </reference>
        <reference name="category.products">
            <action method="insert">
                <child>breadcrumbs</child>
            </action>
        </reference>
    </catalog_category_layered>

Put above code in your xml and in view.phtml add child html below where you want to show breadcrumb.

<?php echo $this->getChildHtml('breadcrumbs');?>
| improve this answer | |

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.