Last updated March 5, 2010. Created by glass.dimly on March 5, 2010.
Log in to edit this page.

This snippet adds <span class="breadcrumb-$number"></span> to each breadcrumb link. This is useful if you have a fixed number of breadcrumbs on certain pages and wish to customize, say, the second breadcrumb link.

Paste this into your template.php file. Make sure to remove the php tags and to replace yourthemename with, you guessed it, your theme name.

<?php
function yourthemename_breadcrumb($breadcrumb) {
  if (empty(
$breadcrumb)) {
    return
$themed_breadcrumb = '<div id="breadcrumb"></div>';
  }
  else  {
   
$themed_breadcrumb = '<div id="breadcrumb">';
   
$array_size = count($breadcrumb);
   
$i = 0;
    while (
$i < $array_size) {
     
$themed_breadcrumb .= '<span class="breadcrumb-';
     
$themed_breadcrumb .= $i;
     
$themed_breadcrumb .=  '">' . $breadcrumb[$i] . '</span>';
      if (
$i + 1 != $array_size ) {
       
$themed_breadcrumb .=  ' >> ';
      }
     
$i++;
    }
   
$themed_breadcrumb .= '</div>';
    return
$themed_breadcrumb;
  }
}
?>

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Thanks for getting me started with this. I need a first and last for my breadcrumbs. I modified the code to add a second class

If $1 is equal to 0 add my second class "first-crumb"

If $i + 1 is equal to the array count add second class "last-crumb"

I have it working on my system, but this is my first time sharing/modifying a snippet so please let me know if something is wrong with this version.

function phptemplate_breadcrumb($breadcrumb) {
  if (empty($breadcrumb)) {
    return $themed_breadcrumb = '<div id="breadcrumb"></div>';
  }
  else  {
    $themed_breadcrumb = '<div id="breadcrumb">';
    $array_size = count($breadcrumb);
    $i = 0;
    while ( $i < $array_size) {
      $themed_breadcrumb .= '<span class="breadcrumb-';
      $themed_breadcrumb .= $i;
      if ($i == 0) {
$themed_breadcrumb .= ' first-crumb';
      }
      if ($i+1 == $array_size) {
$themed_breadcrumb .= ' last-crumb';
      }
      $themed_breadcrumb .=  '">' . $breadcrumb[$i] . '</span>';
      if ( $i + 1 != $array_size ) {
        $themed_breadcrumb .=  ' >> ';
      }
      $i++;
    }
    $themed_breadcrumb .= '</div>';
    return $themed_breadcrumb;
  }
}

<?php
function yourthemename_breadcrumb($breadcrumb) {
  if (empty(
$breadcrumb)) {
    return
$themed_breadcrumb = '<div id="breadcrumb"></div>';
  }
  else {
   
$themed_breadcrumb = '<div id="breadcrumb">';
   
$array_size = count($breadcrumb['breadcrumb']);
   
$i = 0;
    while (
$i < $array_size ) {
     
$themed_breadcrumb .= '<span class="breadcrumb-';
     
$themed_breadcrumb .= $i;
     
$themed_breadcrumb .=  '">' . $breadcrumb['breadcrumb'][$i] . '</span>';
      if (
$i + 1 != $array_size ) {
       
$themed_breadcrumb .=  ' › ';
      }
     
$i++;
    }
   
$themed_breadcrumb .= '</div>';
    return
$themed_breadcrumb;
  }
}
?>