Skip to content

Instantly share code, notes, and snippets.

@backflip
Created December 2, 2011 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save backflip/1423699 to your computer and use it in GitHub Desktop.
Save backflip/1423699 to your computer and use it in GitHub Desktop.
WordPress: Navigations
<?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