简体   繁体   中英

Can't get my dropdown working in a Bootstrap based Wordpress theme

I've tried lots of examples from this site. And a couple have worked. But only when I use them in a html file, and not a php as is the index for Wordpress.

Funny feeling it's the javascript not loading.

Also, I can't get the collapse to work work properly. Just makes the whole menu disappear.

Latest version of Bootstrap is used.

Here's my code:

<link href = "<?php bloginfo ('stylesheet_url'); ?>" rel = "stylesheet">
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.video-ui.js"></script>
<script type="text/javascript">  $('#demo1').videoUI(); </script>

<div class="container">
  <button class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse">
       <span class = "icon-bar"></span>
       <span class = "icon-bar"></span>
       <span class = "icon-bar"></span>
  </button>

  <div class = "collapse navbar-collapse navHeaderCollapse">
  <div class="header">                        
    <ul class="nav nav-pills pull-right">
      <li><a href = "#">Home</a></li>
      <li><a href = "#">Blog</a></li>
      <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" href="#">Social Media<span class="caret"></span></a>
            <ul class = "dropdown-menu">
              <li><a href = "#">Twitter</a></li>
              <li><a href = "#">Facebook</a></li>
              <li><a href = "#">Google+</a></li>
              <li><a href = "#">Instagram</a></li>
            </ul>
      </li>
      <li><a href = "#">About</a></li>
      <li><a href = "#">Contact</a></li>
    </ul>
    <h3 class="text-muted"><small>Jumbotron Narrow</small></h3>
  </div>
  </div>

Thank you for your time.

Andy

Since you where using wordpress surely that you had a wrong path..store your js in your themes folder then just add <?php bloginfo('template_directory'); ?>/ <?php bloginfo('template_directory'); ?>/ in your src..your header will look like this:

<link href = "<?php bloginfo ('stylesheet_url'); ?>" rel = "stylesheet">
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.video-ui.js"></script>
<script type="text/javascript">  $('#demo1').videoUI(); </script>

The other way in wordpress is like this:

function sudo_plugin_scripts() {
    wp_enqueue_script('jquery_script', plugin_dir_url( __FILE__ ).'js/jquery-1.10.2.js');
    wp_enqueue_script('bootstrap_script', plugin_dir_url( __FILE__ ).'js/bootstrap.min.js');
    wp_enqueue_style('video_script', plugin_dir_url( __FILE__ ).'js/jquery.video-ui.js');
}

add_action('wp_enqueue_scripts','sudo_plugin_scripts');

add those scripts in your functions.php

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

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