0

I'm pretty new to the world of drupal so I'm hoping this will be a quick fix.

Anyhow here's the situation: my breadcrumbs work correctly when hitting a node for example when i go to "contact" it prints out home > contact. Now I have a view and when I go there things look ok. I go to events and it prints out home > events > view all. When I go to a subview like "tech events" however it spits out home > events > events > view all.

The code below is what is currently in place so I was wondering how to alter it to handle views or if anyone could point me to a good solution.

thank you

my code:

function custom_breadcrumb($variables) {
  $currentTitle = "";
  $trail = menu_get_active_trail();
  $currentNode = array_pop($trail);
  if( $currentNode ){
    $currentTitle = $currentNode['title'];
  }

  $breadcrumb = $variables['breadcrumb'];
  if (!empty($breadcrumb)) {

    $output = '<ul class="breadcrumb"><li>';
    $output .= implode('</li><li class="breadcrumb-seperator"><!--&raquo;--></li><li class="breadcrumb-seperator-border"></li><li>', $breadcrumb);

    if( $currentTitle ){
      $output .= '</li><li class="breadcrumb-seperator"><!--&raquo;--></li><li class="breadcrumb-seperator-border"></li><li class="active">';
      $output .= $currentTitle;
    }
    $output .= '</li></ul>';

    return $output;
  }
}

any help would be awesome guys. thank you.

0

Okay so it still needs some work to be a little more generic but this basically handles the case. It checks to make sure that the content-type is not a node we check to see if there's an additional argument and append that to the breadcrumbs. if it is a node we just print out hte breadcrumb trail checking to make sure that we don't repeat things. If you use a page jump, fragments, or redirects you might get a repeat, i.e. home > stories > stories. So here it is.

function custom_breadcrumb($variables) {
  $currentTitle = "";
  $trail = menu_get_active_trail();
  $currentNode = array_pop($trail);
  if( $currentNode ){
    $currentTitle = $currentNode['title'];
  }

  $breadcrumb = $variables['breadcrumb'];
  if (!empty($breadcrumb)) {
    $lastCrumb = NULL;

    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

    $output .= '<ul class="breadcrumb"><li>';

  for ($i = 0; $i < count($breadcrumb); $i++) {
    $curCrumb = strip_tags($breadcrumb[$i]);
    if ($i == 0) {
      $output .= $breadcrumb[$i];
      $lastCrumb = strip_tags($breadcrumb[$i]);
    } elseif (strpos($breadcrumb[$i], $lastCrumb) === false) {
      $output .= '</li><li class="breadcrumb-seperator" data-test="testing"><!--&raquo;--></li><li class="breadcrumb-seperator-border"></li><li>' . $breadcrumb[$i];
      $lastCrumb = strip_tags($breadcrumb[$i]);
    }
  }

  if (arg(0) != 'node' ) {
    $output .= '</li><li class="breadcrumb-seperator"><!--&raquo;--></li><li class="breadcrumb-seperator-border"></li><li class="active">';
    $output .= arg(1);
  } elseif( $currentTitle ){
    $output .= '</li><li class="breadcrumb-seperator"><!--&raquo;--></li><li class="breadcrumb-seperator-border"></li><li class="active">';
    $output .= $currentTitle;
  }
  $output .= '</li></ul>';

  return $output;
  }
}
0

To be honest, I'd probably skip all the custom stuff and just use Path Breadcrumbs

This module is a solution for all problems with the breadcrumbs on your site!

Path Breadcrumbs module helps you to create breadcrumbs for any page with any selection rules and load any entity from the URL!

They're also exportable, so if you want them in code you can either export them and implement the default hook, or use Features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.