Created
December 2, 2011 15:48
-
-
Save backflip/1423699 to your computer and use it in GitHub Desktop.
WordPress: Navigations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register navigations | |
*/ | |
register_nav_menus(array( | |
'main' => __('Main navigation', THEME_TEXTDOMAIN), | |
'meta' => __('Meta navigation', THEME_TEXTDOMAIN) | |
)); | |
/** | |
* Add custom class for current menu item (and its ancestors) | |
*/ | |
function theme_current_menu_classes($classes = array(), $menu_item = false){ | |
$map = array( | |
'current-menu-item' => 'current', | |
//'current-menu-parent' => 'current', // Use something else if this should look different | |
'current-menu-ancestor' => 'current' // Use something else if this should look different | |
); | |
foreach ($map as $key => $value) { | |
if (in_array($key, $menu_item->classes)) { | |
$classes[] = $value; | |
} | |
} | |
return $classes; | |
} | |
add_filter('nav_menu_css_class', 'theme_current_menu_classes', 10, 2); | |
/** | |
* Custom navigation walker for main navigation (adds dropdown containers) | |
*/ | |
class theme_walker_nav_main extends Walker_Nav_Menu { | |
function start_lvl(&$output, $depth) { | |
$output .= '<div class="dd"><div><ul>'; | |
} | |
function end_lvl(&$output, $depth) { | |
$output .= '</ul></div></div>'; | |
} | |
} | |
/** | |
* In Theme | |
*/ | |
wp_nav_menu(array( | |
'theme_location' => 'main', | |
'container' => false, | |
'link_before' => '<span>', | |
'link_after' => '</span>', | |
'walker' => new theme_walker_nav_main | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment