Trailing Separators when using Zen based themes and Custom Breadcrumbs

Dev

Trailing Separators when using Zen based themes and Custom Breadcrumbs

by Sean Corrales
//

Trailing Separators when using Zen based themes and Custom Breadcrumbs

While using the Custom Breadcrumbs module to implement breadcrumbs on Views pages for a client’s site, I encountered an issue where my breadcrumbs had an extra separator appended at the end of my breadcrumbs but only on the Views pages. This left me with breadcrumbs like:

“Home > People > Search > Results > “
 
instead of:

“Home > People > Search > Results”.

On my theme’s configuration, I have the “Append the content title to the end of the breadcrumb” option checked. Unchecking this option removes the trailing “>” but now all my other breadcrumbs lack the page’s title at the end of the breadcrumb.

I copied over Zen’s breadcrumb function to my template.php and made a few simple modifications. If you have a zen based theme and want to use Custom Breadcrumbs, try adding this function to your theme’s template.php. Remember to change the function name (zen_breadcrumb) to match your theme’s name (yourtheme_breadcrumb).

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return
 *   A string containing the breadcrumb output.
 */
function zen_breadcrumb($breadcrumb) {
  // Determine if we are to display the breadcrumb.
  $show_breadcrumb = theme_get_setting('zen_breadcrumb');
  if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {

    // Optionally get rid of the homepage link.
    $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
    if (!$show_breadcrumb_home) {
      array_shift($breadcrumb);
    }

    // Return the breadcrumb with separators.
    if (!empty($breadcrumb)) {
      $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
      $trailing_separator = $title = '';
      if (theme_get_setting('zen_breadcrumb_title')) {
        $trailing_separator = $breadcrumb_separator;
        $title = menu_get_active_title();

        //Check for empty title and kill separator if necessary.
        if($title == ''){
            $trailing_separator = '';
        }
      }
      elseif (theme_get_setting('zen_breadcrumb_trailing')) {
        $trailing_separator = $breadcrumb_separator;
      }
      return '";
    }
  }
  // Otherwise, return an empty string.
  return '';
}

Even if a Views page has a menu entry and page title, it’s title is not returned by the menu_get_active_title() function. I’ve added a simple if/then statement that checks for a title and, if it’s empty, it sets the separator as an empty value, as well.  I haven’t tested it but I think similar issues would arise with panels. This snippet should take care of those issues.

More About the Author

Sean Corrales

Lead Web Developer
Internet Explorer ignoring CSS files Like most web developers, I do most of my development work in one browser (in my case, Firefox) and then do cross browser checks after ...
Creating checkout panes for Ubercart All code comes from a shipping insurance module I wrote for Ubercart. I plan to release it on ubercart.org and drupal.org after I ...

See more from this author →

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072

×

Love our blog? You should see our emails. Sign up for our newsletter!