Wordpress Nav菜单子页面

时间:2013-11-17 14:12:16

标签: php css wordpress

我有一个自定义主题的wordpress,当我添加一个页面,它自动显示在菜单中,我已经添加了我想在菜单中显示的子页面,但菜单只扩展到1级,我想要显示3个级别,如

热门导航菜单

产品 - >硬件 - >戴尔 - >笔记本电脑                              - >桌面

这样的事情。生成菜单的代码如下,请帮助我

    <section id="nav-container">
    <section class="container_12">
    <section class="grid_12"> 
        <!-- #nav start -->
        <nav id="nav">
          <ul>
            <li><span class="nav-icon icon-home"></span> <a href="<?php echo home_url( '/' ); ?>">Home</a></li>
            <?php

        $wpmenu = new WP_Query(array('post_type' => 'page','post_status' => 'publish', 'post_parent' => '0','order' => 'ASC','orderby' => 'menu_order'));
        $myi = 1;
        if($wpmenu->have_posts()): while($wpmenu->have_posts()): $wpmenu->the_post();
        $icon = get_post_meta(get_the_ID(), "icon", TRUE);
        ?>  
            <li><span class="nav-icon icon-<?php echo $icon;?>"></span>
            <a href="<?php echo the_permalink(); ?>"><?php echo the_title(); ?></a>
            <?php
            $submenu2 = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_parent = '".get_the_ID()."' ORDER BY menu_order ASC";
            if($menu3 = $wpdb->get_results($submenu2, OBJECT))
            {
                echo "<ul>";
                foreach($menu3 as $menu4)
                {
                ?>
                <li><a href="<?php echo get_permalink($menu4->ID); ?>"><?php echo $menu4->post_title; ?></a></li>
                <?php
                }
                echo "</ul>";
            }
            else
            {
                echo "</li>";   
            }
            ?>
            <?php
            $myi++;
            endwhile; endif;
            wp_reset_query();
            ?>
            </li>
          </ul>
        </nav>
        <!-- #nav end --> 

        <!-- responsive navigation start -->
        <select id="nav-responsive">
          <option value="<?php echo home_url( '/' ); ?>">Home</option>
          <?php
        $active = "";
        $wpmenu = new WP_Query(array('post_type' => 'page','post_status' => 'publish', 'post_parent' => '0','order' => 'ASC','orderby' => 'menu_order'));
        if($wpmenu->have_posts()): while($wpmenu->have_posts()): $wpmenu->the_post();
          ?>
          <option value="<?php echo get_permalink(); ?>">
          <?php the_title();?>
          </option>
          <?php
          endwhile; endif;
          wp_reset_query();
          ?>
        </select>
        <!-- responsive navigation end -->

        <section id="search-box">
          <form action="<?php echo esc_url( home_url( '/' ) ); ?>" role="search" method="get" id="searchform">
            <input id="m_search" name="s" type="text" placeholder="Type and hit enter..." />
            <input class="search-submit" type="submit" id="searchsubmit" />
          </form>
        </section>
      </section>
      <!-- .grid_12 end --> 
    </section>
    <!-- .container_12 end --> 

  </section>
  <!-- #nav-container end --> 

1 个答案:

答案 0 :(得分:0)

我建议使用免费的Multi-level Navigation插件,让您完全控制导航中显示的链接。它非常容易安装,并提供了一个可视编辑器的链接,以便您可以像下载网站一样设置下拉菜单。