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
版权声明:本文标题:theme development - Custom loop menu is not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736620322a1945560.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论