2011-09-10 38 views
-1

的Drupal 7:我需要環繞麪包屑文本span標籤,這是我

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; 
    } 
} 

這種輸出格式,我需要其他比我需要添加周圍裏面的文本span標籤的麪包屑鏈接。

的聯繫正被寫入第七行從底部:

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

任何想法?

+0

鏈接在哪裏? – ajreal

+0

它在數組內:$ breadcrumb [$ i]在某處。我不是最好的PHP,或者這可能會更容易。 –

+0

可以包含$ breadcrumb [$ i]的一些示例數據嗎? – ajreal

回答

2

因爲我看不到的$breadcrumb[$i]裏面的內容我不能完全肯定,這將工作,但下面的代碼應該爲你工作,因爲它封裝了一個錨標籤裏的任何東西,跨度標籤:

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

只需用這兩行替換函數中的第七行,看​​看它是否有效!否則,在$breadcrumb[$i]上使用var_dump並將結果添加到您的問題中。

+0

謝謝,完美無缺! –

相關問題