From 383fc7fc4f9f3d85487ca3e272f42baaadfc4c07 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 26 Aug 2015 16:08:14 -0400 Subject: [PATCH] Update mobile navigation Adding a custom menu walker for the off canvas menu so it is grabing the main site menu from appearance menu. --- functions.php | 60 +++++++++++++++++++++++++++++++++++++++ parts/off-canvas-menu.php | 3 +- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index f25ba12..3ac6420 100644 --- a/functions.php +++ b/functions.php @@ -109,6 +109,31 @@ class Mountpleasantcvb_Top_Bar_Walker extends Walker_Nav_Menu { } endif; +/** + * Mobile off-canvas + */ +if ( ! function_exists( 'mountpleasantcvb_mobile_off_canvas' ) ) { + function mountpleasantcvb_mobile_off_canvas() { + echo ''; + } +} if ( ! function_exists( 'mountpleasantcvb_footer' ) ) { function mountpleasantcvb_footer() { wp_nav_menu(array( @@ -128,6 +153,41 @@ if ( ! function_exists( 'mountpleasantcvb_footer' ) ) { } } +if ( ! class_exists( 'Mountpleasantcvb_Offcanvas_Walker' ) ) : +class Mountpleasantcvb_Offcanvas_Walker extends Walker_Nav_Menu { + + function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { + $element->has_children = ! empty( $children_elements[ $element->ID ] ); + $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; + $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'page_item_has_children' : ''; + $element->classes[] = 'page_item'; + + parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); + } + + function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { + $item_html = ''; + parent::start_el( $item_html, $object, $depth, $args ); + + $classes = empty( $object->classes ) ? array() : (array) $object->classes; + + if ( in_array( 'label', $classes ) ) { + $item_html = preg_replace( '/]*>(.*)<\/a>/iU', '', $item_html ); + } + + $output .= $item_html; + } + + function start_lvl( &$output, $depth = 0, $args = array() ) { + $output .= "\n'; + } + +} +endif; /** * glm_page_menu * diff --git a/parts/off-canvas-menu.php b/parts/off-canvas-menu.php index 16b5e40..1756831 100644 --- a/parts/off-canvas-menu.php +++ b/parts/off-canvas-menu.php @@ -1,5 +1,6 @@