0

I have a parent menu item which is taxonomy name. I want to add in a mega menu with a featured post from the menu taxonomy in the left of the sub menu.

This code works and shows displays the html correctly, but I'm not sure how to get the parent menu item text (To query the featured post details).

public function end_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat( "\t", $depth );
    $output .= "$indent</ul></div><div class=\"col-md-8\">Featured Post</div></div>\n";
}

How could I get the parent menu item text inside the end_lcl function?

public function end_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat( "\t", $depth );
    // This is the piece I'm missing
    $parent_menu_item_text = ??????;
    $args = array( 'taxonomy' => $parent_menu_item_text );
    // Query the post with the $args etc..
    $output .= "$indent</ul></div><div class=\"col-md-8\">Featured Post</div></div>\n";
}

I've seen this answer but seems like the the class code has been updated since then (2013)

  • you will have to do it in start_el the menu item object is not passed to end_lvl – David Lee Feb 24 '17 at 17:12
  • How do I pass it through the start_el? – BenB Feb 24 '17 at 18:42
  • the menu item is already being passed in start_el as $item – David Lee Feb 24 '17 at 20:03
  • This is the question, how could it be passed somehow to the end_lvl – BenB Feb 24 '17 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.