I'm building a drop down menu with additional box aside the sub menus with information from custom meta box from the parent menu page. The issue I ran into is I cant get the parent menu item id in the end_lvl function. Is it possible using the $db_fields array to get that?
her's is my custom walker class:
thanks for any help here
function check_for_submenu($classes, $item) {
global $wpdb;
$has_children = $wpdb->get_var("SELECT COUNT(meta_id) FROM wp_postmeta WHERE meta_key='_menu_item_menu_item_parent' AND meta_value='".$item->ID."'");
if ($has_children > 0)
array_push($classes,'first-level has-drop-down');
else
array_push($classes,'first-level');
return $classes;
}
add_filter( 'nav_menu_css_class', 'check_for_submenu', 10, 2);
class dropdown_walker extends Walker_Nav_Menu
{
var $link_counter=0;
var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
function start_lvl(&$output, $depth) {
global $link_counter;
$class = 'drop-down';
$indent = str_repeat("\t",$depth);
$output .= "\n$indent<ul class=\"$class\" >\n";
$output .= '<div class="menu_open_right">
<div class="menu_open_head">
<p></p>
</div>';
}
function end_lvl(&$output, $depth, $db_fields) {
$output .= '</div>
<div class="menu_open_left">
<div class="menu_open_feat_box">';
$args = array(
'p' => //dont know how to get the parent menu item id,
);
$the_query = new WP_Query($args);
while ( $the_query->have_posts() ) : $the_query->the_post();
$output .= ' <span>'. /* dont know how to get the parent menu item id */.'</span>';
$output .= ' <img src="' . get('home_page_snippet_image'). '" /> ';
$output .= get('home_page_snippet_desc') ;
$output .= ' <p><a href="">read more +</a></p>';
endwhile;
$output .= ' <div class="menu_duck"></div>
</div>
</div>';
$output .= '</ul>';
}
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
global $link_counter;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
if (in_array('first-level has-drop-down',$classes)) $counter++;
$output .= $indent . '<li ' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
if (strpos($class_names,'first-level has-drop-down')) {
$link_counter++;
$attributes .= ' class="link-drop-down" ';
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before .apply_filters( 'the_title', $item->title, $item->ID );
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}