我如何在wp_nav_menus中使用<li>和<a>类?

时间:2019-11-24 15:04:16

标签: wordpress menu wordpress-theming

我如何在wp_nav_menus中使用<li><a>类?

<div class="collapse navbar-collapse" id="ftco-nav">
    <ul class="navbar-nav nav ml-auto">
        <li class="nav-item"><a href="#home-section" class="nav-link"><span>Home</span></a></li>
        <li class="nav-item"><a href="#about-section" class="nav-link"><span>About</span></a></li>
        <li class="nav-item"><a href="#skills-section" class="nav-link"><span>Skills</span></a></li>
        <li class="nav-item"><a href="#projects-section" class="nav-link"><span>Projects</span></a></li>
        <li class="nav-item"><a href="#blog-section" class="nav-link"><span>My Blog</span></a></li>
        <li class="nav-item"><a href="#contact-section" class="nav-link"><span>Contact</span></a></li>
    </ul>
</div>

1 个答案:

答案 0 :(得分:0)

    <ul class="list-unstyled nav1 cl-effect-10">
        <li class="Home"><a  data-hover="Home" class="active"><span>Home</span></a></li>
        <li class="About"><a data-hover="About"  href="about.html"><span>About</span></a></li>
        <li class="Rooms"><a data-hover="Rooms"  href="rooms.html"><span>Rooms</span></a></li>
        <li class="Gallery"><a data-hover="Gallery"  href="gallery.html"><span>Gallery</span></a></li>
        <li class="Dinning"><a data-hover="Dinning" href="dinning.html"><span>Dinning</span></a></li>
        <li class="News"><a data-hover="News" href="news.html"><span>News</span></a></li>
        <li><a data-hover="Contact Us" href="contact.html"><span>contact Us</span></a></li>
    </ul>
  </div>

plz请尝试以下代码:

   <?php
     $location=get_nav_menu_locations();
     $menuid =$location['header'];
     $primarymenu = wp_get_nav_menu_items($menuid);
   ?>
 <ul class="list-unstyled nav1 cl-effect-10 ">
      <?php
        foreach($primarymenu as $key=>$value)
        {
      ?>
        <li class="<?php echo $value->title; ?>"><a data-hover="<?php echo $value->title;?>"  href="<?php echo $value->url; ?>"><span><?php echo $value->title; ?></span></a></li>
      <?php   
        }
      ?>
 </ul>
</div>