WordPress 中的 Nivo Slider jQuery 插件不会旋转图像。我该如何解决这个问题?
我正在将 nivo slider jQuery 插件添加到 WordPress 主题,但我无法让图像旋转。它们都加载但不旋转。这是我的标题中适用于滑块的部分:
<?php wp_enqueue_script('jquery'); ?>
<?php wp_head(); ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/nivo-slider.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/default.css" type="text/css" media="screen" />
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
jQuery(window).load(function() {
jQuery('#slider').nivoSlider();
});
</script>
这是显示图像的 div:
<div id="slider" class="nivoSlider">
<?php
$slides = $data['pingu_slider']; //get the slides array
foreach ($slides as $slide) {
echo '<h1 class="image_title">' .$slide['title'].'</h1>';
echo '<img src="'.$slide['url'].'" alt="test">';
echo '<p class="nivo-caption">' .$slide['description'].'</p>';
}
?>
</div>
滑块所在的站点位于 http://sandbox.nspirelab.com/
I am adding the nivo slider jQuery plugin to a WordPress theme but I can't get the images to rotate. They all load but they don't rotate. Here is the section of my header that applies to the slider:
<?php wp_enqueue_script('jquery'); ?>
<?php wp_head(); ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/nivo-slider.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/default.css" type="text/css" media="screen" />
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
jQuery(window).load(function() {
jQuery('#slider').nivoSlider();
});
</script>
And here is the div where the images are being displayed:
<div id="slider" class="nivoSlider">
<?php
$slides = $data['pingu_slider']; //get the slides array
foreach ($slides as $slide) {
echo '<h1 class="image_title">' .$slide['title'].'</h1>';
echo '<img src="'.$slide['url'].'" alt="test">';
echo '<p class="nivo-caption">' .$slide['description'].'</p>';
}
?>
</div>
The site where the slider is located is at http://sandbox.nspirelab.com/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的页面上,您将加载 jQuery 两次...版本 1.4 紧随版本 1.4.2 之后。
但一个主要问题是,您在
head
中调用jQuery
,但 jQuery 直到body
中才存在。在包含插件或调用代码之前,您需要包含 jQuery。仅包含 jQuery 一次,然后包含您的插件,然后调用您的函数。这可以在
head
或body
中完成。最后,由于我们正在讨论 Wordpress 主题,因此请看一下使用
enqueue
来防止多次加载 jQuery。http://codex.wordpress.org/Function_Reference/wp_enqueue_script
On your page, you're loading jQuery twice.... version 1.4 right after version 1.4.2.
But one major issue is that you're calling
jQuery
in yourhead
but jQuery does not even exist yet until down in thebody
. You need to include jQuery before you include the plugins or call the code.Only include jQuery once, then include your plugin, and then call your function. This can be done in either the
head
or thebody
.And finally, since we're talking about a Wordpress theme, take a look at using
enqueue
to prevent the loading of jQuery multiple times.http://codex.wordpress.org/Function_Reference/wp_enqueue_script