简体   繁体   English

WordPress的导航菜单不起作用

[英]wordpress navigation menu not working

I am starting theme development with bootstrap. 我正在使用引导程序开始主题开发。 I got problem with navigation menu. 我的导航菜单有问题。

In header.php header.php中

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

In functions.php functions.php中

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

What's wrong here ? 怎么了 I am newbie and developing wordpress theme for first time 我是新手,并且是第一次开发wordpress主题

Here is full header.php 这是完整的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 UPDATE

I have removed all array items, now it's working. 我删除了所有数组项,现在可以正常工作了。 But I didn't understand what's exact problem ? 但是我不明白确切的问题是什么?

<?php
            wp_nav_menu( array(

            ));     
        ?>  

In Your header.php put below code and try 在您的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM