E
E
Eugene Rudoi2016-01-31 12:14:56
WordPress
Eugene Rudoi, 2016-01-31 12:14:56

WordPress Menu starting from level 2?

Hello
Help with this task
There is a main menu in the header of the site which has the Services item in the first level and it has a 2nd level and a 3rd one.
On the internal pages of the Services, you need to display the side menu only from the sub-items of the services. I understand that you can create a separate menu for these services, but since there are a lot of them, I would not like to fill out the menu several times.
How can I display the menu so that it displays items starting from the 2nd level ???
Is there any equivalent property

'depth'  => 0, // (integer) Глубина вложенности (0 - неограничена, 2 - двухуровневое меню)

Thanks for the help !

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2016-01-31
@wppanda5

Do based on this How to get the id of all the pages that are used in the wordpress menu?

I
Ivan Kozlov, 2016-02-01
@trampick

<?php
    $menu_name = 'top-menu';//Здесь указываем локацию твоего меню
    $locations = get_nav_menu_locations();
    if (isset($locations[$menu_name])) {
      $menu = wp_get_nav_menu_object($locations[$menu_name]);
      $menu_items = wp_get_nav_menu_items($menu->term_id);
      foreach ($menu_items as $i) {//перебираем все элементы этого меню. Нам нужны те элементы, у которых есть родитель.
        if ($i->menu_item_parent != 0) {
          echo '<a href="' . $i->url . '">';
          echo $i->title;
          echo '</a>';
        }
      }
    }
  ?>

This code will output all elements of the 2nd and 3rd levels. If nesting is necessary, then you will have to finish the conditions a little :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question