开发者

I need to wrap span tags around breadcrumb text, this is what I have

Drupal 7:

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

    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here:') . '</h2>';
    $crumbs = '<ul class="breadcrumbs clearfix">';
    $array_size = count($breadcrumb);
    $i = 0;
    while ( $i < $array_size) {
      $crumbs .= '<li class="breadcrumb-' . $i;
      if ($i == 0) {
        $crumbs .= ' first';
      }
      if($i != 0 && $i+1 != $array_size ) {
        $crumbs .= ' middle';
      }
      if ($i+1 == $array_size) {
        $crumbs .= ' last';
      }
      $crumbs .=  '">' . $breadcrumb[$i] . '</li>';
      $i++;
    }
    $crumbs .= '</ul>';
    return $crumbs;
  }
}

This outputs the breadcrumbs in the format I need other than I need to add 开发者_开发知识库span tags around the text inside the link.

The link is being written in the seventh line from the bottom:

  $crumbs .=  '">' . $breadcrumb[$i] . '</li>';

Any ideas?


Since I can't see the content inside of $breadcrumb[$i] I can't be completely sure that this will work, but the following code should work for you as it wraps anything inside an anchor tag with a span tag:

preg_match("@<a ([^>]+)>(.+)</a>@i", $breadcrumb[$i], $matches);
$crumbs .=  '"><a ' . $matches[1] . '><span>' . $matches[2] . '</span></a></li>';

Just replace the seventh line in your function with these 2 lines and see if it works! Otherwise, use var_dump on $breadcrumb[$i] and add the result to your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜