Is there anyway to add the current page title on drupal 7 breadcrumb?
5 Answers
Some themes - like Zen - provide this option, so check under Appearance -> Settings. If your theme doesn't offer the option, you can edit your theme's page.tpl.php - simply add $title
after the $breadcrumb
variable. Alternatively you could override theme_breadcrumb()
.
You could also use the Menu breadcrumb module to do this (it has D6 and D7 versions too).
It allows you to
"Append the page title to the breadcrumb (either as a clickable url or not)"
See this tutorial:
Tutorial - How to Work and Style Breadcrumbs in Drupal 7
As a side note, if you are coding your breadcrumb trail in the template.php file, the page title will be added in the breadcrumbs to any [custompage].tpl.php file automatically.
I am not saying it's a better way of doing it. Personally, it was a more convenient solution for me, as i have multiple [page].tpl.php files.
(I also changed the default output to <li>
list items, in order to get the CSS markup right.)
function templatename_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
$crumbs = '';
if (!empty($breadcrumb)) {
$crumbs = '<div id="breadcrumbs"><span>You are here: </span><ul>';
foreach($breadcrumb as $value) {
$crumbs .= '<li>' . $value . '</li>';
}
$crumbs .= '<li>' . drupal_get_title() . '</li></ul></div>';
}
return $crumbs;
}
Maybe this is of some help to anyone.
-
-
1ah, yes, I had left out some parts of my code of which I thought they were irrelevant in my answer. Apparently, I was a bit too enthousiastic in stripping the code. Thank you for noticing, I have updated my post. Commented Nov 29, 2011 at 13:05
You could use the Custom Breadcrumbs module it has an option where you can include the current page title (or any other token field)
If you want to have breadcrumb in a block, you can create a block with the following content:
<?php
$bcarr = drupal_get_breadcrumb();
$bcarr [] = drupal_get_title();
print theme('breadcrumb', array('breadcrumb'=>$bcarr));
?>
This is for Drupal 7 and the content type should be PHP code.