简体   繁体   中英

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
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.

<!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.

<?php wp_footer(); ?> 

Would love it if someone could explain to me why this would cause bootstrap drop down menus to stop working.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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