From d4d4779da861613095762f3f108cd409cdc4445d Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 23 Jun 2016 16:00:12 -0400 Subject: [PATCH] Put the menu item parent title into sub menu Tricky one here. Need to save the object when it is at the depth of 0. --- lib/menu-walker.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/menu-walker.php b/lib/menu-walker.php index 64b5a96..c7f2d74 100644 --- a/lib/menu-walker.php +++ b/lib/menu-walker.php @@ -17,14 +17,20 @@ class Glm_Theme_Top_Bar_Walker extends Walker_Nav_Menu { } function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { + static $saveParent = 0; $item_html = ''; parent::start_el( $item_html, $object, $depth, $args ); + //echo '
$object: ' . print_r($object, true) . '
'; // Insert style to display page's thumbnail $item_style = ''; - if ($depth == 0 && has_post_thumbnail((int)$object->object_id)) { - $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id((int)$object->object_id), 'large'); - $item_style .= ""; + if ( $depth == 0 ) { + $saveParent = $object; + } + if ( $depth != 0 ) { + // get the page title from parent + $title = get_the_title( $saveParent->object_id ); + $output .= '
  • ' . $title . '

  • '; } //$output .= ( 0 == $depth ) ? '
  • ' : ''; $classes = empty( $object->classes ) ? array() : (array) $object->classes; @@ -35,8 +41,9 @@ class Glm_Theme_Top_Bar_Walker extends Walker_Nav_Menu { if ( in_array( 'divider', $classes ) ) { $item_html = preg_replace( '/]*>( .* )<\/a>/iU', '', $item_html ); } - if ($item_style) + if ($item_style) { $output .= $item_style; + } $output .= $item_html; } -- 2.17.1