V
V
vvvadimos2016-01-08 19:18:56
PHP
vvvadimos, 2016-01-08 19:18:56

How to write Walker_Nav_Menu class for menu sublists?

Help me write a class that will generate an adequate menu, namely:
let's say the menu structure is like this:

<ul>
  <li>
    <a></a>
  </li>
  <li>
    <a></a>
    <ul>
      <li>
        <a></a>
      </li>
    </ul>
  </li>
</ul>

I would like to end up with something like this:
<ul class="main-menu">
  <li class="menu-item">
    <a class="menu-link"></a>
  </li>
  <li class="menu-item">
    <a class="menu-link"></a>
    <ul class="sub-menu">
      <li class="menu-item-1">
        <a class="menu-link-1"></a>
      </li>
    </ul>
  </li>
</ul>

those. sublist elements with their own classes. And all this without any .menu-item-'id' that WordPress generates. you only need to leave the class that indicates that the page in the menu is currently displayed, such as current-page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Kudryavtsev, 2016-01-08
@vvvadimos

Walker class documentation for WP
As a ready-made example, you can look at wp-bootstrap-navwalker
Read, analyze, write. I don't have any ready-made code for such a task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question