2015-11-20 175 views
1

我开始主题发展与引导。导航菜单出现问题。WordPress的导航菜单不工作

的header.php

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

的functions.php

register_nav_menus(array(
    'primary' => esc_html__('Primary Menu', 'test1-wp-theme'), 
)); 

有什么不对吗?我是新手,开发wordpress主题首次

这里充满的header.php

<?php 
/** 
* The header for our theme. 
* 
* This is the template that displays all of the <head> section and everything up until <div id="content"> 
* 
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials 
* 
* @package T1_WP 
*/ 

?><!DOCTYPE html> 
<html <?php language_attributes(); ?>> 
<head> 
<meta charset="<?php bloginfo('charset'); ?>"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="profile" href="http://gmpg.org/xfn/11"> 
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>"> 
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/bootstrap.min.css"> 
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/main.css"> 

<?php wp_head(); ?> 
</head> 

<body <?php body_class(); ?>> 
<div id="page" class="site"> 
    <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e('Skip to content', 'test1-wp-theme'); ?></a> 
<nav class="navbar navbar-inverse navbar-fixed-top"> 
     <div class="container"> 
     <div class="navbar-header"> 
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> 
      <span class="sr-only">Toggle navigation</span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      </button> 
      <a class="navbar-brand" href="#">ABC Blog</a> 
     </div> 
     <?php 
      wp_nav_menu(array(
       'theme_location' => 'primary', 
       'container'   => 'nav', 
       'container_class' => 'navbar-collapse collapse', 
       'menu_class'  => 'nav navbar-nav navbar-right' 
      ));  
     ?>  

     </div> 
    </nav> 

    <div id="content" class="site-content"> 

UPDATE

我已删除了所有的数组项,现在它的工作。但我不明白什么是确切的问题?

<?php 
      wp_nav_menu(array(

      ));  
     ?> 
+0

你的代码看起来还好,你有没有分配给主菜单位置菜单? –

+0

只需添加<( '主', 'theme_location'=> '初级', 'menu_class'=> 'NAV导航栏-NAV导航栏右')的PHP wp_nav_menu阵列( '菜单'=)?>; ?> 貌似容器 –

+0

感谢的问题,它的工作现在:) – NeosFox

回答

2

在你的header.php把下面的代码,并尝试

<div id="navbar(Id Name)" class="your class name"> 
    <?php 
       wp_nav_menu(array(
        'menu' => 'primary', 
        'theme_location' => 'primary', 
        'container_class' => 'navbar-collapse collapse', 
        'menu_class'  => 'nav navbar-nav navbar-right' 
       ));  
    ?> 
</div> 
+0

它不工作,同样的问题 – NeosFox

+0

@madanBhandari我们已经更新了答案,并尝试把你的wp_nav_menu功能特别股利和分配你的菜单主菜单的位置为好 。 –

+0

我试过了,但没有工作。我已经通过仪表板将菜单分配给主菜单。 – NeosFox