-2

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.

  • The terminology you've used here is incorrect to the point that I'm struggling to understand exactly what you're trying to do. Perhaps it would be helpful to add an image to the question to demonstrate what you mean? – Simba May 15 '17 at 13:42
  • As @Simba says, it's impossible to know what you are actually trying to do. Please give screenshot(s) and code samples. We'd love to help, but need more info and with clarity. – Phill Healey May 15 '17 at 13:51
  • https://www.w3.org/WAI/ has that kind of menu. You click a link, you get a new page and an expanded menu. I can do the same with my WP menu, but only with CSS. I want to do it server-side. I included the CSS so you can see what I need: first hide all the sub-
      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

1 Answers1

0

If i understand correctly the second thing you want to display is something called "breadcrumbs". Here is example solution for that: PHP Simple dynamic breadcrumb Also you can google many of other solutions for breadcrumbs if you need.

You can echo your menu with php and then operate on that section with php but still to format it visually you still need css as this is purpose of css. For example:

echo('<ul>');
  echo('<li><a href="index.php">Home</a></li>');
  echo('<li><a href="news.php">News</a></li>');
  echo('<li><a href="contact.php">Contact</a></li>');
  echo('<li><a href="about.php">About</a></li>');
echo('</ul>');

Let this be just a hint for you how to achieve what you expect.

Community
  • 1
  • 1
spectatorx
  • 373
  • 2
  • 7
  • 22
  • No. There are tens of plugins to do breadcrumbs. I just need a tool or technique that could act as the CSS code I gave in the first place, but server-side and physically remove the menu items that are not needed at the moment. It should be HTML class based, just as it is in the CSS. – user3273017 May 15 '17 at 19:18