Display full Breadcrumb in node
description
If you have a "listing page" of nodes organized by taxonomy, for example, a page called /taxonomy/term/4, the list itself returns the correct breadcrumb but when you click on one of the node titles or "read more" links, the individual node opens with the breadcrumb apparently "broken"; all that shows up is "Home".
The "correct" behavior would be to show the full breadcrumb (everything up to the listing page title AND the category title) in the node's breadcrumb.
This snippet set customizes the node template (usually node.tpl.php) in your theme to do just. (This works with themes using phptemplate in 4.6 and 4.7)
Step 1 of 6
Make a copy of node.tpl.php and...
In your original node.tpl.php, put the following code at the very top:
<?php
$listing = false;
if(arg(0) == 'taxonomy')
{
$listing = true;
}
if($listing)
{
$bc = drupal_get_breadcrumb();
$title = drupal_get_title();
$title = html_entity_decode($title,ENT_QUOTES);
$link = l($title,$_GET['q']);
$bc[] = $link;
$bc_safe = urlencode(serialize($bc));
?>Step 2 of 6
In the original node display code that is right after what you've just pasted in, look for the line that displays the title. Usually it's something like:
<a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a>
Replace that line with:
<?php print l($node->title, "node/$node->nid",array(),"bc=$bc_safe"); ?>
Step 3 of 6
Now look in the original code for the line that prints "$links" ($links includes the "read more" link - thank you Zach!) and replace THAT line with
print l("read More", "node/$node->nid",array('class' => 'read-more'),"bc=$bc_safe");
Step 4 of 6
At the end of the node display code insert:
<?php
}
else {
if(isset($_GET['bc']))
{
$bc = unserialize($_GET['bc']);
}
drupal_set_breadcrumb($bc);
?>Step 5 of 6
Copy the original node display code from your old node.tpl.php copy and paste it under your the above statement. You don't have to change anything in it this time.
Step 6 of 6
At the very bottom of that pasted code, put in:
<?php
}
?>Save it and your node page will now display a Drupal-consistent breadcrumb.
example node.tpl.php
To help contextualize this better, here's a sample node.tpl.php with these snippets applied:
<?php
$listing = false;
if(arg(0) == 'taxonomy')
{
$listing = true;
}
if($listing)
{
$bc = drupal_get_breadcrumb();
$title = drupal_get_title();
$title = html_entity_decode($title,ENT_QUOTES);
$link = l($title,$_GET['q']);
$bc[] = $link;
$bc_safe = urlencode(serialize($bc));
?>
<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">
<?php if ($page == 0): ?>
<h2><?php print l($node->title, "node/$node->nid",array(),"bc=$bc_safe"); ?>
</h2>
<?php endif; ?>
<?php print $picture ?>
<div class="info"><?php print $submitted ?></div>
<div class="content">
<?php print $content ?>
</div>
<?php if ($links): ?>
<?php if ($picture): ?>
<br class='clear' />
<?php endif; ?>
<div class="links"><?php
print l("read More", "node/$node->nid",array('class' => 'read-more'),"bc=$bc_safe");
?></div>
<?php endif; ?>
<div class="terms"> <?php print $terms ?> </div>
</div>
<?php
}
else {
?>
<?php
if(isset($_GET['bc']))
{
$bc = unserialize($_GET['bc']);
}
drupal_set_breadcrumb($bc);
?>
<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">
<?php if ($page == 0): ?>
<h2><?php print l($node->title, "node/$node->nid"); ?>
</h2>
<?php endif; ?>
<?php print $picture ?>
<div class="info"><?php print $submitted ?></div>
<div class="content">
<?php print $content ?>
</div>
<?php if ($links): ?>
<?php if ($picture): ?>
<br class='clear' />
<?php endif; ?>
<div class="links"><?php print $links ?></div>
<?php endif; ?>
<div class="terms"> <?php print $terms ?> </div>
</div>
<?php
}
?>
There's also a Taxonomy Breadcrumb
The Taxonomy Breadcrumb module does something very similar to this without theme hacks. It also works when the "bc" variable isn't set on the request (for example, they reached the page from search).