简体   繁体   English

无法在基于Bootstrap的Wordpress主题中使用下拉菜单

[英]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. 但是只有当我在html文件而不是php中使用它们时,Wordpress的索引才使用。

Funny feeling it's the javascript not loading. 有趣的是,这是javascript无法加载。

Also, I can't get the collapse to work work properly. 另外,我无法使折叠正常工作。 Just makes the whole menu disappear. 只是使整个菜单消失。

Latest version of Bootstrap is used. 使用最新版本的Bootstrap。

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'); ?>/ 既然您肯定在使用wordpress的地方输入了错误的路径,请将js存储在主题文件夹中,然后只需添加<?php bloginfo('template_directory'); ?>/ <?php bloginfo('template_directory'); ?>/ in your src..your header will look like this: <?php bloginfo('template_directory'); ?>/在您的src ..标题中将如下所示:

<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: 在WordPress中的另一种方式是这样的:

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 将这些脚本添加到您的functions.php中

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

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

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