| 7 theme.inc | theme_breadcrumb( |
| 4.6 theme.inc | theme_breadcrumb($breadcrumb) |
| 4.7 theme.inc | theme_breadcrumb($breadcrumb) |
| 5 theme.inc | theme_breadcrumb($breadcrumb) |
| 6 theme.inc | theme_breadcrumb( |
| 8 theme.inc | theme_breadcrumb($variables) |
Returns HTML for a breadcrumb trail.
Parameters
$variables: An associative array containing:
- breadcrumb: An array containing the breadcrumb links.
Related topics
4 theme calls to theme_breadcrumb()
- BlogTestCase::verifyBlogs in modules/
blog/ blog.test - Verify the logged in user has the desired access to the various blog nodes.
- ForumTestCase::verifyForums in modules/
forum/ forum.test - Verifies that the logged in user has access to a forum nodes.
- ForumTestCase::verifyForumView in modules/
forum/ forum.test - Verifies display of forum page.
- template_process_page in includes/
theme.inc - Process variables for page.tpl.php
File
- includes/
theme.inc, line 1793 - The theme system, which controls the output of Drupal.
Comments
Here is a way to put Breadcrumbs in a UL
PermalinkHere is something I needed to figure out, and thought I would share:
<?php/* Put Breadcrumbs in a ul li structure */
function YOURTHEME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty(
$breadcrumb)) {$crumbs = '<ul class="breadcrumbs">';
foreach(
$breadcrumb as $value) {$crumbs .= '<li>'.$value.'</li>';
}
$crumbs .= '</ul>';
}
return $crumbs;
}
?>
Breadcrumb as an unordered list with unique and first/last class
PermalinkI needed a way to add a background image to work as a separator between the breadcrumbs rather than HTML characters so I came up with this using the above example as a starting point.
This allows you to have unique classes such as "breadcrumb-1" and "breadcrumb-2" so you can target the specific list items as well as a "first" and "last" class added to the list items.
Add this to your theme's template.php and theme as needed.
<?php/**
* Output breadcrumb as an unorderd list with unique and first/last classes
*/
function YOURTHEME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$crumbs = '<ul class="breadcrumbs clearfix">';
$array_size = count($breadcrumb);
$i = 0;
while ( $i < $array_size) {
$crumbs .= '<li class="breadcrumb-' . $i;
if ($i == 0) {
$crumbs .= ' first';
}
if ($i+1 == $array_size) {
$crumbs .= ' last';
}
$crumbs .= '">' . $breadcrumb[$i] . '</li>';
$i++;
}
$crumbs .= '</ul>';
return $crumbs;
}
}
?>
Thanks for that - helped me
PermalinkThanks for that - helped me out a lot for appending on the current note title. Here is my complete code:
<?php// Ouptuts site breadcrumbs with current page title appended onto trail
function YOURTHEME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$crumbs = '<div class="breadcrumb">';
$array_size = count($breadcrumb);
$i = 0;
while ( $i < $array_size) {
$crumbs .= '<span class="breadcrumb-' . $i;
if ($i == 0) {
$crumbs .= ' first';
}
/* if ($i+1 == $array_size) {
$crumbs .= ' last';
} */
$crumbs .= '">' . $breadcrumb[$i] . '</span> » ';
$i++;
}
$crumbs .= '<span class="active">'. drupal_get_title() .'</span></div>';
return $crumbs;
}
}
?>
$output not being returned with $crumbs
Permalinkthe <h2> is not being returned
needs something like
$output .= $crumbs;
return $output;
That's because
Permalinkthere's a typo in the code:
this line
$crumbs = '<div class="breadcrumb">';should be
$crumbs .= '<div class="breadcrumb">';That line, uncorrected, wipes the earlier assignment of the string and replaces it with the
Page jumps / hash links
PermalinkJust to add to the above examples, I had a scenario where we were using page jumps as sub menu items, these caused a repeat in the menu, i.e.
Home > Features > Features,
I've added some code that stops this from happening, thought I'd share as may be useful for others, people will need to add in the first and last class code as before (not needed in our implementation)
<?php
function YOURTHEME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
$breadcrumb = array_unique($breadcrumb);
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$crumbs = '<div class="breadcrumb">';
$array_size = count($breadcrumb);$i = 0;
while ( $i < $array_size) {
$pos = strpos($breadcrumb[$i], drupal_get_title());
//we stop duplicates entering where there is a sub nav based on page jumps
if ($pos === false){
$crumbs .= '<span class="breadcrumb-' . $i;
$crumbs .= '">' . $breadcrumb[$i] . '</span> > ';
}
$i++;
}
$crumbs .= '<span class="active">'. drupal_get_title() .'</span></div>';
return $crumbs;
}
}
?>
Using a breadcrumb separator
PermalinkUsing a breadcrumb separator image
<?php function MYTHEME_breadcrumb($variables) {$breadcrumb = $variables['breadcrumb'];
if (!empty(
$breadcrumb)) {// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$breadcrumb_separator = '<span class="breadcrumb-separator"> </span>';
$output .= '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . '</div>';
return $output;
}
}
?>
and css:
.breadcrumb-separator {background:url(../images/separator-image.png) no-repeat center center;
}
Add the page title to the breadcrumb
PermalinkAdd the following function to your theme to add the current page title to the breadcrumb:
function MYTHEME_breadcrumb($variables) {$variables['breadcrumb'][] = drupal_get_title();
return theme_breadcrumb($variables);
}
Where does the function
PermalinkWhere does the function (function MYTHEME_breadcrumb) get put? Into template.php?
Correct
PermalinkCorrect, the
MYTHEME_breadcrumbfunction gets put into template.phpoverride breadcrumb from module
Permalinkhey there,
maybe I'm in the wrong place to ask, but - how can I override the breadcrumb from a module, if the module functions are executed before the theme's?
any help is greatly appreciated.
Why not just use Drupal's great theme functions for ul lists:
Permalinkfunction theme_breadcrumb($variables) {if (!empty($variables['breadcrumb'])) {
$crumbs = "";
$variables['breadcrumb'][] = '<span class="active">' . drupal_get_title() . '</span>';
$breadcrumb = $variables['breadcrumb'];
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$output .= theme('item_list', array(
'items' => $breadcrumb,
'type' => 'ul',
'attributes' => array('id' => 'main-breadcrumbs', 'class' => array('breadcrumbs')),
)
);
return $output;
}
}
double title
PermalinkDear all,
this is what i do with my template.php
$breadcrumb = $variables['breadcrumb'];$crumbs ='';
$title = $variables['breadcrumb'];
$title[] = drupal_get_title();
if (!empty($breadcrumb)) {
$crumbs = '<ul id="breadcrumbs">';
foreach($breadcrumb as $value) {
$crumbs .= '<li>'.$value.'</li>';
}
$crumbs .= '<li>'.drupal_get_title().'</li></ul>';
}
return $crumbs;
it show double title in my poll result http://web.pn-pontianak.go.id/node/55/results but other page just print one title.
please let me know if anything wrong with that code
regards
mbahlol
And my another one variant :)
Permalink<?phpfunction theme_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
$show_home = theme_get_setting('show_home');
if (!$show_home && $breadcrumb[0] == l(t('Home'), '<front>')) {
array_shift($breadcrumb);
}
$count = count($breadcrumb) - 1;
$items = array();
foreach($breadcrumb as $key => $value) {
if($count != $key) {
$d = filter_xss(theme_get_setting('breadcrumb_delimiter'));
$items[] = $value . '<span class="divider">' . (empty($d) ? '/' : $d) . '</span>';
}else{
$items[] = $value;
}
}
$return = array(
'#theme' => 'item_list',
'#items' => $items
);
return drupal_render($return);
}
}
?>
Another variant
PermalinkUsing various codes from above, I compiled the following:
<?php
function MYTHEME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
$crumb_arrow = '<span class="crumbs-arrow"> » </span>';
if (!empty(
$breadcrumb)) {$arr_crumbs = array();
array_push($arr_crumbs, '<span class="crumbs">' . implode($crumb_arrow, $breadcrumb) . '</span>');
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$array_size = count($arr_crumbs);
for (
$i=0; $i < $array_size; $i++) {if ( $i == $array_size - 1 ) {
// Menu link title may override the content title
(menu_get_active_title()) ? $current_crumb = menu_get_active_title() : $current_crumb = drupal_get_title();
// If current page is 'Edit Page'
if (substr(drupal_get_title(), 0, 18) == '<em>Edit Page</em>') {
$current_crumb = 'Edit';
}
$output .= $arr_crumbs[$i] . '<span class="crumbs-current">' . $crumb_arrow . $current_crumb . '</span>';
break;
}
$output .= $arr_crumbs[$i];
}
return '<div class="breadcrumb">' . $output . '</div>';
}
}
?>