我已经将 nivo slider 插件添加到 wordpress,但是它没有移动到 git 加载文件之外。我相信问题出在我加载 jquery 的方式上。
我在主题文件夹内的 js 文件夹中包含了 javascript jquery.nivo.slider.js 文件。 在 header.php 中,我在 head 标签中使用了这个:
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/bootstrap/js/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>
在 index.php 中我使用了这个:
<div class="container">
<div class="slider-wrapper theme-default">
<div class="ribbon"></div>
<div id="slider" class="nivoSlider">
<img src="bootstrap/images/screen1.jpg"/>
<img src="bootstrap/images/screen2.jpg" />
<img src="bootstrap/images/screen3.jpg" />
<img src="bootstrap/images/screen4.jpg"/>
</div>
</div>
我没有在 functions.php 文件中使用任何东西。我在 style.css 中使用它:
@import url("bootstrap/css/nivo-slider.css");
@import url("bootstrap/css/slider.css");
@import url("bootstrap/css/bootstrap.css");
@import url("bootstrap/themes/default/default.css");
你能告诉我我哪里出错了吗,因为出现的是 git 文件而不是图像幻灯片。当用作 index.html 时,它很有魅力。
最佳答案
查看两个链接可能会解决问题,如果您使用入队标准,则可能会解决 jquery 冲突。 http://codex.wordpress.org/Function_Reference/wp_register_script
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
创建一个script.js文件
$(window).load(function() {
$('#slider').nivoSlider();
});
打开主题文件 functions.php 并添加以下代码:
创建函数
function enqueue_script_for_nivo () {
wp_enqueue_script('jquery');
// Load your nivo script too here.
wp_register_script('nivoscript',get_stylesheet_directory_uri().'/bootstrap/js/jquery.nivo.slider.pack.js"');
wp_register_script( 'my-script', get_stylesheet_directory_uri() . '/js/script.js' );
wp_enqueue_script('nivoscript');
wp_enqueue_script('my-script');
}
add_action('wp_enqueue_scripts','enqueue_script_for_nivo');
这就是全部尝试这个希望它应该工作:)
关于javascript - Nivo slider 在 wordpress jquery 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21657192/