jeudi 29 janvier 2015

How do you add content to a WordPress sub-menu dependant in its parent?


What I'm wanting to achieve is this: A submenu with content showcasing 1 product from each category after the links In the submenu.


I am trying to use the WordPress nav walker to add the content after the closing submenu tag. This I can do.


The question is how I differentiate the content based on its parent menu item.


Thanks in advance and any questions welcome.


I'm using standard wordpress menus and woocommerce.


I am using the 'end_lvl' function to add content after the submenu. I just need to know how to differentiate between the different submenus generated by creating an if statement checking its parents id. Im not sure how to do this.



class Custom_Walker_Nav_Menu extends Walker_Nav_Menu {
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);

//$test = $item->object_id;
$check = $item->ID;

if ( $check == 255 ) {
$test = "boop";
} else {
$test = "bleep";
}

$output .= "<div class=\"menu-content\">" . $test . "</div>$indent</ul>\n";
}}


How can I output the ID (to check) so I can differentiate between the different submenus and output different content accordingly using the above if statement?





Aucun commentaire:

Enregistrer un commentaire