سؤال

Currently, I have this working on my template.php

function systema_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];
  $crumbs = null;
  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $crumbs .= '<ul class="breadcrumb">';
    $array_size = count($breadcrumb);
    $i = 0;
    while ( $i < $array_size) {
      $crumbs .= '<li>' . $breadcrumb[$i] . '</li>';
      $i++;
    }
    $crumbs .= '<li><span>'. drupal_get_title() .'</span></li></ul>';
    return $crumbs;
  }
}

The output of this displays as Home > [Content Type] > [Page Title]

While this works fine, there is something missing here. The current URL structure I set this page to is mydomain.com/[content-type]/[field-value]/[title-slug]. The [field-value] is a field that I added when you create a content based on its type. It is using a select list based on taxonomy terms I created. Here's what I want:

  1. Set the breadcrumbs based on the URL.
  2. Display them as unordered list.
  3. Set the last item as <span> instead of <a> tag.

The hierarchical approach works like this. My only problem with that is it is displaying as a div. I want to set them as unordered list. Can anyone help me modify this or does anyone have a better approach? Thanks!

هل كانت مفيدة؟

المحلول

Follow the example that you linked to however instead of the line:

return '<div class="breadcrumb">'. implode(' &raquo; ', $breadcrumb) .'</div>';

Put:

// wrap last array element in a span
end($breadcrumb);
$breadcrumb[key($breadcrumb)] = '<span>'.$breadcrumb[$key].'</span>';

// now loop each item and build a ul
$out = '<ul class="breadcrumb">';
foreach($breadcrumb as $item) {
    $out .= '<li>'.$item.'</li>';
}
return $out .= '</ul>';
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top