I would want to make a very specific menu with wp_nav_menu that only load the main menu elements and the submenu element of a main menu element if it has been selected.
Exemple:
Menu1
+Submenu1 +Submenu2 Menu2 Menu3
I don't 开发者_开发百科want to hide the other submenus using CSS.
I also want to add a "+" before each submenu element.
How can I do this using wp_nav_menu function?
Thanks a lot for your help.
You can filter the results of wp_nav_menu by using my plugin here.
As far as adding the + signs to the specific sub-children use JQuery. Something like this... (Place this code directly above your end body tag.)
<script type="text/javascript">
$(document).ready(function (){
$('#UNIQUE_PARENT_ELEMENT .current-menu-item > a ').prepend('+ ');
});
</script>
Make sure that you have JQuery loaded and that you replace your #UNIQUE_PARENT_ELEMENT with say... #sidebar if your wp_nav_menu is located in
<div id="sidebar">
//NAV MENU IS IN HERE
</div>
Here is a way to customize your menu with a walker_nav_menu : http://goldenapplesdesign.com/2010/10/05/dropdown-menus-walker_nav_menu/ and use & adapt this :
// If this is a sub-menu element
if( $depth == 1) {
$item_output .= $another_link_before .apply_filters( ‘the_title’, $item->title, $item->ID );
}else{
$item_output .= $args->link_before .apply_filters( ‘the_title’, $item->title, $item->ID );
}
精彩评论