2015-06-02 105 views
0

我试图用这个有道理图库我发现[http://miromannino.github.io/Justified-Gallery/][1]麻烦与enqueue_scripts的画廊插件

[1]:http://miromannino.github.io/Justified-Gallery/本网站www.dangoodeofficial.co.uk

我设法得到它的工作通过添加这是页脚 -

<script src="http://dangoodeofficial.co.uk/wp-content/plugins/Justified-Gallery/libs/jquery/jquery.min.js"></script> 

<link rel="stylesheet" href="http://dangoodeofficial.co.uk/wp-content/plugins/Justified-Gallery/dist/css/justifiedGallery.min.css" type="text/css" media="all"> 

<script src="http://dangoodeofficial.co.uk/wp-content/plugins/Justified-Gallery/dist/js/jquery.justifiedGallery.min.js"></script> 

但jquery.min.js弄乱我的网站的其余部分。从以前的问题我问我相信这是因为Wordpress已经内置jQuery,但我只能让画廊显示,当我将jquery.min.js包含在页脚中时。

我一直在试图找出如何排队脚本,因为我相信这是解决我的问题的方式。我从来没有这样做过,所以我不知道从哪里开始。我做我的研究,我已将此添加到我的孩子主题的functions.php

// Additional Functions 
// ============================================================================= 
function justifiedGallery() { 

    wp_enqueue_script('jQuery'); 

    wp_register_script('JG_jQuery_js', get_template_directory_uri() . '/plugins/Justified-Gallery/libs/jquery/jquery.min.js', array('jQuery'),'', true); 
    wp_register_script('JG_js', get_template_directory_uri() . '/plugins/Justified-Gallery/dist/js/jquery.justifiedGallery.min.js', array('jQuery'),'', true); 
    wp_register_style('JG_css', get_template_directory_uri() . '/plugins/Justified-Gallery/dist/css/justifiedGallery.min.css', '','','screen'); 


    wp_enqueue_script('JG_jQuery_js'); 
    wp_enqueue_script('JG_js'); 
    wp_enqueue_style('JG_css'); 

} 

    add_action ('wp_enqueue_scripts', 'justifiedGallery'); 

但我就是不能完全似乎得到它的工作。我甚至尝试将我想要调用的三个文件上传到我的子主题目录,以便文件路径为/wp-content/themes/x-child/js/jquery.justifiedGallery.min.js以及类似的两个文件并使用

get_stylesheet_directory_uri() . 'js/.justifiedGallery.min.js', array('jQuery'),'', true);

我知道有可能只是一个简单的错误的地方,但我的知识有限,我无言以对。非常感激任何的帮助。

谢谢

回答

0

真正的问题似乎是一个写得不好的插件,需要你所有的JavaScript手动复制到您的模板和手动包括它,而不是管理它本身。

由于手动包括jQuery的页脚中的混乱与您现有的网站,很可能已被包含在您的模板的jQuery。如果你想确保它只被调用一次,并且不想使用它们内置的jQuery版本,那么首先必须注销WP已经拥有的JQ版本,而不是注册你自己的版本。试试这个:

function externalJQ() { 
    if(! is_admin()) { 
    // Register and Enqueue External jQuery in Footer 
    wp_deregister_script('jquery'); 
    wp_register_script('jquery', "https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", array(), null, true); // Or whatever version of JQ you want 
    wp_enqueue_script('jquery'); 
    } 
} 
add_action('wp_enqueue_scripts', 'externalJQ'); 

也就是说,使用jQuery的不应该要求的jQuery值得的盐任何插件被绑定到$命名空间(这可能是问题的一部分,我没有通过的代码插件),你不应该做任何这一点。

此外,插件本身应该调用它需要的任何JavaScript。如果你需要在你的模板中包含任何插件的JavaScript,你可能想要避开这个插件。

+0

嗨,杰克,谢谢你的回应。我想我可能会问错误的问题。我想我真的需要知道的是,我如何使这个http://miromannino.github.io/Justified-Gallery(http://miromannino.github.io/Justified-Gallery)从gitHub的jQuery插件工作在我的WordPress的网站?谢谢,丹 –