I'm trying to create a nav menu with a clickable dropdown function but minimize scripting at the same time, so I found out a way to achieve this with an invisible input box and CSS. My only problem is I have no experience with PHP and getting the menu to load the right HTML is very frustrating (it took me forever just to get the custom walker to show up in the first place). This is the effect I want to achieve - the same default WordPress menu, but the menu items with children are slightly different:
<ul>
<li>A menu item</li>
<li>A menu item</li>
<li>
<input id="check-(item-id)" type="checkbox" />
<label for="check-(item-id)">A menu item with children</label>
<ul>
<li>Child one</li>
<li>Child two</li>
</li>
<li>A menu item</li>
</ul>
In my functions.php file, I have this:
<?php
/*---- Custom Menu Settings ----*/
function custom_menus() {
$locations = array(
"top-menu" => __( "Top Menu" ),
"side-menu" => __( "Side Menu" ),
);
register_nav_menus( $locations );
}
add_action( "init", "custom_menus" );
class Clickable_Dropdown_Walker extends Walker_Nav_Menu {
// The code isn't even worth showing because I've tried at least a dozen combinations and nothing's worked
}
?>
And finally, in my sidebar.php I have this:
<?php
if ( has_nav_menu( "side-menu" ) ) {
wp_nav_menu( array(
"theme_location" => "side-menu",
"container_class" => "side-menu",
"walker" => new Clickable_Dropdown_Walker() ) );
}
?>
Any help would be appreciated, thanks!