Zam*_*uuz 1 wordpress-theming collapse togglebutton twitter-bootstrap twitter-bootstrap-3
我正在使用Bootstrap v3.0.2开发响应式wordpress主题.
在移动/平板电脑浏览器而不是整个菜单中,我需要显示Bootstrap切换按钮.我的按钮显示,但是当我点击它时没有发生任何事情.这是我在我写的代码header.php:
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Run Code Online (Sandbox Code Playgroud)
我写的那个function.php:
function wpt_register_js() {
wp_register_script(
'jquery.bootstrap.min',
get_template_directory_uri() . '/js/bootstrap.min.js',
'jquery'
);
wp_enqueue_script('jquery.bootstrap.min');
}
add_action( 'init', 'wpt_register_js' );
function wpt_register_css() {
wp_register_style(
'bootstrap.min',
get_template_directory_uri() . '/css/bootstrap.min.css'
);
wp_enqueue_style( 'bootstrap.min' );
}
add_action( 'wp_enqueue_scripts', 'wpt_register_css' );
Run Code Online (Sandbox Code Playgroud)
footer.php代码包含:
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<?php wp_footer();?>
</body>
Run Code Online (Sandbox Code Playgroud)
header.php包含:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php wp_title('|', true, 'right'); ?></title>
<link href="<?php echo get_template_directory_uri(); ?>/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="<?php echo get_template_directory_uri(); ?>/css/style.css" rel="stylesheet" type="text/css">
<?php wp_head(); ?>
</head>
Run Code Online (Sandbox Code Playgroud)
这个问题通过使用Bass Jobsen的答案来解决.谢谢朋友
请先阅读http://getbootstrap.com/components/#navbar.您的导航栏需要javascript:
如果禁用JavaScript并且视口足够窄以致导航栏崩溃,则无法展开导航栏并查看.navbar-collapse内的内容.
确保在文档中包含bootstrap.js.你忘了上传这个吗?
根据您问题中的新信息进行更新:
将所有javascripts和css排入functions.php并从header.php和footer.php中删除它们
JavaScript的:
function skematik_jquery_js(){
wp_enqueue_script('jquery');
}
function wpt_register_js() {
wp_register_script(
'jquery.bootstrap.min',
get_template_directory_uri() . '/js/bootstrap.min.js',
'jquery'
);
wp_enqueue_script('jquery.bootstrap.min');
}
/* Load Scripts */
add_action( 'wp_enqueue_scripts', 'skematik_jquery_js' );
add_action( 'wp_enqueue_scripts', 'wpt_register_js' );
Run Code Online (Sandbox Code Playgroud)
CSS:
function wpt_register_css() {
wp_register_style(
'bootstrap.min',
get_template_directory_uri() . '/css/bootstrap.min.css'
);
wp_enqueue_style( 'bootstrap.min' );
}
add_action( 'wp_enqueue_scripts', 'wpt_register_css' );
Run Code Online (Sandbox Code Playgroud)