[英]Nivo slider not working in wordpress jquery
我已經將nivo滑塊插件添加到了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');
那就全部嘗試一下,希望它可以工作:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.