Answer the question
In order to leave comments, you need to log in
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 - двухуровневое меню)
Answer the question
In order to leave comments, you need to log in
Do based on this How to get the id of all the pages that are used in the wordpress menu?
<?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>';
}
}
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question