2017-07-29 144 views
2

這是HTML代碼,而不包括UL李標籤中的PHP:引導導航欄類工作不正常

<html> 
<body> 
    <div class="container-fluid"> 
     <div class="row"> 
      <div class="text-center" style="margin-top: 15px;"> 
       <span><h2><?php bloginfo('name'); ?></h2></span> 
        <p><h6><?php bloginfo('description'); ?></h6></p> 
      </div>    
     <nav class="navbar navbar-default"> 
      <ul class="nav navbar-nav"> 
       <li><a href="#">Home</a></li> 
       <li><a href="#">Lifestyle</a></li> 
       <li><a href="#">Adventure</a></li> 
       <li><a href="#">Fashion<span class="caret"></span></a></li> 
       <li><a href="#">Travel</a></li> 
       <li><a href="#">Story</a></li> 
      </ul>    
     </nav> 
    </div> 
</body> 
</html> 

這是PHP的HTML代碼中包含了UL李標籤中:

<html> 
<body> 
    <div class="container-fluid"> 
     <div class="row"> 
      <div class="text-center" style="margin-top: 15px;"> 
       <span><h2><?php bloginfo('name'); ?></h2></span> 
       <p><h6><?php bloginfo('description'); ?></h6></p> 
      </div>   
     <nav class="navbar navbar-default stroke"> 
      <ul class="nav navbar-nav">    
       <?php 
        $args = array(
         'theme_location' => 'primary',       
        ); 

       ?> 
       <li><?php wp_nav_menu($args);?></li>      
      </ul>    
     </nav> 
    </div> 
</body> 
</html> 

這裏的導航欄像這樣工作的圖像: Working code image

下面是不加載css類的導航欄圖像: Image which is not loading css and links are different b'cause theme development function is called

回答

0

我們將編寫代碼,以顯示你的資產淨值

<?php 
      wp_nav_menu(array(
        'theme_location' =>'primary', 
        'container' => 'nav', 
        'container_class' => 'navbar-collapse navbar', 
        'menu_class'  => 'nav navbar-nav navbar-right' 
       )); 
      ?> 

,並刪除該代碼

<nav class="navbar navbar-default stroke"> 
      <ul class="nav navbar-nav">    
       <?php 
        $args = array(
         'theme_location' => 'primary',       
        ); 

       ?> 
       <li><?php wp_nav_menu($args);?></li>      
      </ul>    
     </nav> 
0

添加下面的代碼在你的模板菜單

<html> 
<body> 
    <div class="container-fluid"> 
     <div class="row"> 
      <div class="text-center" style="margin-top: 15px;"> 
       <span><h2><?php bloginfo('name'); ?></h2></span> 
        <p><h6><?php bloginfo('description'); ?></h6></p> 
      </div>    
     <nav class="navbar navbar-default"> 

     <?php 
      $header_menu_defaults = array(
       'theme_location' => 'primary', 
       'menu'   => 'your menu name here', 
       'container'  => '', 
       'container_class' => '', 
       'container_id' => '', 
       'menu_class'  => 'nav navbar-nav', 
       'menu_id'   => '', 
       'echo'   => true, 
       'fallback_cb'  => 'wp_page_menu', 
       'before'   => '', 
       'after'   => '', 
       'link_before'  => '', 
       'link_after'  => '', 
       'items_wrap'  => '<ul id="%1$s" class="%2$s">%3$s</ul>', 
       'depth'   => 0, 
       'walker'   => '' 
      ); 
      wp_nav_menu($header_menu_defaults); 
      ?> 
     </nav> 
    </div> 
</body> 
</html> 
0

如果你想要一個理想的解決方案,你可以使用助行類

有一個像你這樣的問題,你可以從它

訪問此鏈接受到啓發:https://stackoverflow.com/a/11948374/5608642

但如果你想簡單的事情,你可以試試這個代碼

<html> 
<body> 
    <div class="container-fluid"> 
     <div class="row"> 
      <div class="text-center" style="margin-top: 15px;"> 
       <span><h2><?php bloginfo('name'); ?></h2></span> 
       <p><h6><?php bloginfo('description'); ?></h6></p> 
      </div>   
     <nav class="navbar navbar-default stroke"> 
      <ul class="nav navbar-nav">   

       <?php 
        $navLocation = 'primary'; 
        $nav = wp_get_nav_menu_object($navLocation); 
        $navItems = wp_get_nav_menu_items($nav->term_id, array('order' => 'DESC')); 
       ?> 

       <?php foreach($navItems as $item): ?>      
        <?php if (!$item->menu_item_parent): ?> 
          <li><a href="<?= $item->url; ?>"> <?= $item->title; ?> </a> </li> 
        <?php endif; ?> 
       <?php endforeach; ?> 
      </ul>    
     </nav> 
    </div> 
</body> 
</html>