Trailing Separators when using Zen based themes and Custom Breadcrumbs

Trailing Separators when using Zen based themes and Custom Breadcrumbs

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.

Related

Need Expert Help?

See Our Full Menu of Data Services

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!