Nav Walker, why do you hate me? (I'm missing something here)
-
Hi All,
I’d like to just print the main level of navigation on my theme, but capture just the subnav of the immediately selected nav item (if there is one).
I copied the standard Walker class to extend it and made extremely light changes. Essentially at the top of start_el/start_lvl/end_lvl/end_el I check the depth and anything above 0 I just return;.
Pastebin example:
https://pastebin.com/YXXS0ChEAt the bottom of the pastebin you can see what I’m getting for output. To put it here for ease, it’s very simple.
My menu is simple like:
Menu 1 Subnav 1 Menu 2 Menu 3
I want to print the main “Menu #” items. The problem is I’m getting an empty <ul class=”sub-nav”> inside of Menu 1. I do not get the < li > items inside it, just the empty container.
Anyone have any idea why I would get this empty <ul class=”sub-nav”>?
I know I can set the $args to have depth => 1, or just set .sub-nav{display:none;} but I’d really like to understand the Walker class a bit better to start making better navigations.
Thanks for any tips!
- The topic ‘Nav Walker, why do you hate me? (I'm missing something here)’ is closed to new replies.