WordPress无法使jQuery/unlider工作

时间:2016-02-15 作者:Manson Mamaril

我不知道我做错了什么。。。我正在使用初学者木材主题。。。我正在尝试取消滑动以处理我的主题。。。这里指出的是我在从函数中放入脚本时所做的正确证明。php。。。

<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/jquery.js?ver=1\'></script>
<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/resources/bootstrap/js/bootstrap.min.js?ver=1\'></script>
<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/bootstrap-wp.js?ver=1\'></script>
<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/skip-link-focus-fix.js?ver=1\'></script>
<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/unislider/js/unslider-min.js?ver=1\'></script>
<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/stickyFooter.js?ver=1\'></script>
<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/script.js?ver=1\'></script>
<script type=\'text/javascript\' src=\'http://localhost/luxjeweler/wp-includes/js/wp-embed.min.js?ver=4.4.2\'></script>
但不知何故jquery不起作用。。。尝试使用wordpress提供的jquery排队默认值和自定义排队,但未成功。。。我尝试使用以下简单代码进行测试:

$(document).ready(function(){
   alert("test");
}); 
刷新页面时没有响应。。。

编辑(15-02-16):

这是我的排队功能:

function luxjewels_scripts() {

    // Import the necessary TK Bootstrap WP CSS additions
    wp_enqueue_style( \'luxjewels-bootstrap-wp\', get_template_directory_uri() . \'/includes/css/bootstrap-wp.css\', false, \'1\');

    // load bootstrap css
    wp_enqueue_style( \'luxjewels-bootstrap\', get_template_directory_uri() . \'/includes/resources/bootstrap/css/bootstrap.css\', false, \'1\' );

    // load Font Awesome css
    wp_enqueue_style( \'luxjewels-font-awesome\', get_template_directory_uri() . \'/includes/css/font-awesome.min.css\', false, \'1\' );

    // load styles
    wp_enqueue_style( \'luxjewels-style\', get_stylesheet_uri() );

    wp_enqueue_style( \'luxjewels-unslider\', get_template_directory_uri() . \'/includes/unslider/css/unslider.css\', true, \'1\');



    wp_enqueue_script( \'luxjewels-jquery\', get_template_directory_uri() . \'/includes/js/jquery.js\', array(), \'1\', true );

    // load bootstrap js
    wp_enqueue_script(\'luxjewels-bootstrapjs\', get_template_directory_uri().\'/includes/resources/bootstrap/js/bootstrap.min.js\', array(), \'1\', true);

    // load bootstrap wp js
    wp_enqueue_script( \'luxjewels-bootstrapwp\', get_template_directory_uri() . \'/includes/js/bootstrap-wp.js\', array(), \'1\', true);
    wp_enqueue_script( \'luxjewels-skip-link-focus-fix\', get_template_directory_uri() . \'/includes/js/skip-link-focus-fix.js\', array(), \'1\', true );

    // load Unslider js and css
    wp_enqueue_style( \'luxjewels-unslider-dots\', get_template_directory_uri() . \'/includes/unslider/css/unslider-dots.css\',  false, \'1\', true);

    wp_enqueue_script(\'luxjewels-unslider-min\', get_template_directory_uri().\'/includes/unslider/js/unslider-min.js\', array(), \'1\', true);


    // load stickyfooter js
    wp_enqueue_script( \'luxjewels-stickyfooter\', get_template_directory_uri() . \'/includes/js/stickyFooter.js\', array(), \'1\', true );

    // load custom js
    wp_enqueue_script( \'luxjewels-custom-script\', get_template_directory_uri() . \'/script.js\', array(), \'1\', true );

}
add_action( \'wp_enqueue_scripts\', \'luxjewels_scripts\' );

2 个回复
最合适的回答,由SO网友:denis.stoyanov 整理而成

$(document).ready(function(){
   alert("test");
}); 
可能是您的jQuery正在兼容模式下工作。尝试替换$ 使用jQuery:

jQuery(document).ready(function(){
   alert("test");
}); 
编辑:根据作者在帖子上的编辑:

jQuery(document).ready(function(){
   jQuery(\'.automatic-slider\').unslider({
        autoplay: true
    });
}); 

SO网友:Mayeenul Islam

删除此行:

wp_enqueue_script( \'luxjewels-jquery\', get_template_directory_uri() . \'/includes/js/jquery.js\', array(), \'1\', true );
并替换以下行:

wp_enqueue_script( \'luxjewels-custom-script\', get_template_directory_uri() . \'/script.js\', array(), \'1\', true );
使用:

wp_enqueue_script( \'luxjewels-custom-script\', get_template_directory_uri() . \'/script.js\', array(\'jquery\'), \'1\', true );
解释:不用加载我们的自定义jQuery库,我们只需从核心加载jQuery即可。并且声明依赖关系,我们只是通过修改第二行代码来实现这一点。