admin管理员组

文章数量:1125463

I am using the below code to create a custom WordPress menu for mobile. With this code, nothing is return. Even the menu is not retrieving. Can anyone assist me with this? This is a multilingual website and I am using Polylang for the translations.

<?php
$menu_items = wp_get_nav_menu_items('Mobile Menu');

if ($menu_items) {
    echo '<ul class="list-unstyled">';
    foreach ($menu_items as $menu_item) {
        if ($menu_item->menu_item_parent == 0) {
            echo '<li>';
            if (count_menu_items_by_parent($menu_item->ID, $menu_items)) {
                echo '<a class="sub-menu-parent" href="javascript:void(0)">' . $menu_item->title . '</a>';
            } else {
                echo '<a href="' . $menu_item->url . '">' . $menu_item->title . '</a>';
            }
            echo '<ul class="sub-menu">';
            foreach ($menu_items as $sub_menu_item) {
                if ($sub_menu_item->menu_item_parent == $menu_item->ID) {
                    echo '<li><a href="' . $sub_menu_item->url . '">' . $sub_menu_item->title . '</a></li>';
                }
            }
            echo '</ul>';
            echo '</li>';
        }
   }
   echo '</ul>';
}

function count_menu_items_by_parent($parent_ID, $menu_items) {
    $count = 0;
    foreach ($menu_items as $menu_item) {
        if ($menu_item->menu_item_parent == $parent_ID) {
            $count++;
        }
    }
   return $count;
}
?>

本文标签: theme developmentCustom loop menu is not working