Foreach里面的foreach Wordpress MegaMenu

时间:2018-01-15 21:58:49

标签: php jquery html css wordpress

我正在开发一个HTML网站,并使用wordpress作为CMS。我已经在标题中实现了菜单导航,确切地说是MEGA MENU,但我需要这个" ul",进入" foreach"喜欢" li a&#34 ;,因为每个" ul"我需要创建一个列。我是PHP的初学者,想要添加第二个" foreach"在那段代码中,转换了" ul"也是一个循环。

代码在这里:



System.Collections.Generic.Dictionary<ConsoleApp2.TestType,
  System.Collections.Generic.List<ConsoleApp2.TestCase>>
&#13;
&#13;
&#13;

html

&#13;
&#13;
<div class="mainmenu_area">
    <div class="container">
        <nav id="navigation1" class="navigation">
            <!-- toggle -->
            <div class="nav-header">
                <div class="nav-toggle"></div>
            </div>
            <!-- Main Menus Wrapper -->
            <div class="nav-menus-wrapper">
                <ul class="nav-menu">
                    <?php $locations = get_nav_menu_locations();
                    if ( isset( $locations['primary-menu']) ) {
                        $menu = get_term( $locations['primary-menu'], 'nav_menu');
                        if ( $items = wp_get_nav_menu_items( $menu->name ) ) {
                            foreach ( $items as $item ) {
                                if ($item->menu_item_parent != 0) {
                                    continue;
                                }
                                $curNavItemID = $item->ID;
                                $classList = implode(" ", $item->classes);
                                echo "<li class=\"{$classList}\">";
                                echo "<a href=\"{$item->url}\">{$item->title}</a>";
                                if ( in_array('has-mega-menu', $item->classes)) { ?>
                                <div class="megamenu-panel">
                                    <div class="megamenu-lists">

                                        <ul class="megamenu-list list-col-4">
                                        <?php 
                                        foreach ( $items as $subnav) {
                                            if ( $subnav->menu_item_parent == $curNavItemID) {
                                                echo "<li><a href=\"{$subnav->url}\">{$subnav->title}</a>";
                                            }
                                        } ?>


                                    </ul>
                                </div>
                            </div>
                            <?php }
                            echo '</li>';
                        }
                    }
                } ?>
            </ul>
        </div>
    </nav>
</div>
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案