So, I want to make a side menu in WordPress.
It should display:
1) all the first-level links
2) the full "path" to the link that is currently selected
I found out that thanks to the WordPress CSS menu class structure I can emulate the behavior I want to get with this code:
ul#menu-test ul {display:none;}
ul#menu-test li.current-menu-ancestor > ul {display:block;}
ul#menu-test li.current-menu-item > ul {display:block;}
ul#menu-test li.current-menu-item > a {background-color:yellow;}
But I don't want to repeat the whole menu again and just trim it with the CSS, I just want to physically display only the items I really need.
Can I somehow emulate this behavior in PHP? I can pre-fetch the full menu in text format, if that matters.
s (that leaves only the first-level items visible), then find the current menu item, highlight it and display all the ancestral elements leading to that current menu item.
– user3273017 May 15 '17 at 19:21