2014-02-26 119 views
1

我使用NextGen画廊插件为我的wordpress和我自己的脚本为标题滑块。jQuery加载两次wordpress

部首滑块含有:

JS/jquery.min.js JS/responsiveslides.js

我有在functions.php的代码块:

ADD_ACTION( '初始化', 'add_javascript');

function add_javascript() { 
    // Add JQuery 
    wp_enqueue_script('jquery'); 

    // Add the scripts 
    $js_url = get_bloginfo('stylesheet_directory') . '/js'; 
    wp_enqueue_script('jquery-min',"$js_url/jquery.min.js"); 
    wp_enqueue_script('responsiveslides',"$js_url/responsiveslides.min.js"); 
} 

,这在header.php中:

<head> 
<meta charset="<?php bloginfo('charset'); ?>"> 
<meta name="viewport" content="width=device-width"> 
<title><?php wp_title('|', true, 'right'); ?></title> 
<link rel="profile" href="http://gmpg.org/xfn/11"> 
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>"> 
<!--[if lt IE 9]> 
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script> 
<![endif]--> 
<?php wp_head(); ?> 
<script> 
     $(function() { 
    $("#slider").responsiveSlides({ 
    maxwidth: 3200, 
    speed: 800 
    }); 
}); 

<script> 
jQuery(document).ready(function($){ 
$(window).scroll(function(){ 
    if ($(this).scrollTop() > 50) { 
     $('.backToTop').fadeIn('slow'); 
    } else { 
     $('.backToTop').fadeOut('slow'); 
    } 
}); 
$('.backToTop').click(function(){ 
    $("html, body").animate({ scrollTop: 0 }, 500); 
    return false; 
}); 
}); 
</script> 
</head> 

我觉得所以现在画廊工作不正常jQuery是加载两次。我应该如何将代码放在头部滑块和图库上?

这里是我的网站http://193.2.241.108/wordpress/

回答

1

您正在加载jQuery的两倍。

function add_javascript() { 
    // Add JQuery 
    wp_enqueue_script('jquery'); //<--- here 

    // Add the scripts 
    $js_url = get_bloginfo('stylesheet_directory') . '/js'; 
    wp_enqueue_script('jquery-min',"$js_url/jquery.min.js"); //<--- and here 
    wp_enqueue_script('responsiveslides',"$js_url/responsiveslides.min.js"); 
} 

删除您对jQuery的引用之一,并应该解决问题。