我在wordpress博客中建立一個導航。的項目被顯示這樣的:WordPress的wp_nav_menu沃克:動態內容
的圖標是通過使用自舉類glyhicon-glyphiconname
施加。我動態地添加類。對於PHP代碼:
function add_specific_menu_location_atts($atts, $item, $args) {
// check if the item is in the primary menu
if($args->theme_location == 'directentries') {
foreach($item as $key => $value) {
if($key == 'title') {
$catIcon = setCatIcon($value);
}
}
// add the desired attributes:
$atts['class'] = 'btn btn-primary btn-lg glyphicon glyphicon-'.$catIcon;
}
return $atts;
}
add_filter('nav_menu_link_attributes', 'add_specific_menu_location_atts', 10, 3);
$args = array(
'theme_location' => 'directentries',
'depth' => 1,
'container' => false,
'menu_class' => 'nav',
'link_before' => '<br>',
//'link_before' => 'span class"glyphicon"',
'walker' => ''
);
wp_nav_menu($args);
這裏的問題是,該鏈接文字的字體是glyhicon(當然),否則圖標將不適用於鏈接。所以:正確的方法是在初始化菜單時應用範圍使用鏈接 - 在參數之前。 但是我需要將我的動態類名應用於範圍。 我想我可以使用$ args參數我過濾器類中訪問link_before PARAM ..
當前的標記是這樣的: 而我需要的是臨客是: 沒有人有一個想法如何應用跨度和改變類?
。
請加上烏爾導航項目的標記 – Trix
請考慮upvoting有用的答案要感謝的時間和精力的人投資於你的問題 – Trix
當然。這正是我爲什麼在你回答1-2天后回覆你的答案的原因。我也在回答中提到你。你認爲哪種額外的行動來表達我的感激之情? –