简体   繁体   English

wordpress bootstrap下拉菜单不起作用

[英]wordpress bootstrap dropdown menu isn't working

The problem I have is that when I try this code in my theme is works, it produces the menus and all the lists and it gets all of the pages, but it doesn't allow me to expand any of the drop down lists. 我遇到的问题是,当我尝试在主题中运行此代码时,它会生成菜单和所有列表,并且会获取所有页面,但不允许我扩展任何下拉列表。

This is my theme php function.php. 这是我的主题php function.php。

<?php
define('TEMPATH', get_bloginfo('stylessheet_directory'));
define('IMAGES', TEMPATH. "/images");


register_nav_menus( array(
    'primary' => __( 'Primary Menu', 'ClubTheme' ),
) );


wp_register_script('bootstrap-js', get_template_directory_uri() . 
'/bootstrap/js/bootstrap.min.js', array('jquery'), '3.3.7', true);


wp_register_style( 'bootstrap-css', get_template_directory_uri() . 
 '/bootstrap/css/bootstrap.min.css', array(), '', 'all' );

wp_enqueue_script( 'bootstrap-js' );

wp_enqueue_style( 'bootstrap-css' );


require_once('wp-bootstrap-navwalker.php');

require_once('theme-options.php');
/*require_once('/widgets/profile-widget.php');
require_once('/widgets/contact-widget.php');*/
require(get_template_directory() .'/widgets/profile-widget.php');
require(get_template_directory() .'/widgets/contact-widget.php');
require_once('news.php');
require_once('committee-members.php');
 require_once('supporters.php');
 require_once('theme-options.php');



function clubtheme_rewrite() {
global $wp_rewrite;
$wp_rewrite->add_permastruct('typename', 'typename/%year%.%postname%/', true, 
1);

add_rewrite_rule('typename/([0-9]{4})/(.+)/?$',
   'index.php?typename=$matches[2]', 'top');

$wp_rewrite->flush_rules();
}

?>

This is my header.php which contains the code for my menu. 这是我的header.php,其中包含菜单的代码。

<!DOCTYPE html>
<html>
<head>

<title><?php bloginfo ('name'); ?><?php wp_title(); ?></title>
<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> 
<!-- leave this for stats please -->
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="<?php bloginfo ('stylesheet_url');?>" 
type="text/css" media="screen" />
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css" 
type="text/css" media="screen" />   
<?php wp_head(); ?>

</head>

<body>
<nav class="navbar navbar-inverse navbar-static-top" role="Navigation">
  <div class="container-fluid">
            <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-
toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
                        <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="<?php bloginfo('url')?
 >" class="navbar-brand"><?php bloginfo('name');?></a>
            </div>


 <?php
        wp_nav_menu( array(
            'menu'              => 'primary',
            'theme_location'    => 'primary',
            'depth'             => 2,
            'container'         => 'div',
            'container_class'   => 'collapse navbar-collapse',
            'container_id'      => 'bs-example-navbar-collapse-1',
            'menu_class'        => 'nav navbar-nav',
            'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
            'walker'            => new WP_Bootstrap_Navwalker())
        );
    ?>

 </div>
</nav>

我对您的wp_nav_menu使用没有任何错,也许您应该检查队列,尤其是boostrap文件

Not including this at the end of the footer.php file seem to have been the cause of my issue. 在footer.php文件末尾不包括此字符似乎是导致我出现问题的原因。

<?php wp_footer(); ?> 

Would love it if someone could explain to me why this would cause bootstrap drop down menus to stop working. 如果有人可以向我解释为什么这会导致Bootstrap下拉菜单停止工作,将不胜感激。

I did strip back my theme right back to basic, byI tested it after each change through and it wasn't until I added that it worked. 我确实将主题还原为基本主题,我在每次更改后都对其进行了测试,直到我添加了该主题后,我才对其进行测试。

Will start add everything back now, I will add to this answer if it breaks again and what I had to do to fix, three days I spent on this. 现在将开始重新添加所有内容,如果再次出现问题,我将在此答案上加上三天的时间,以解决这个问题。

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

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