简体   繁体   English

使用Zurb Foundation与wordpress不会发生冲突

[英]using Zurb Foundation with wordpress no conflict

I am currently developing a custom theme using foundation and _s I had a few questions.I have followed this tutorial Here enqued all my script etc and now its working. 我目前正在使用Foundation和_s开发自定义主题,我有几个问题。我已按照本教程进行操作, 这里列出了所有脚本等内容,现在可以工作了。

My only concern is the jquery, on some forums is says that i have to deregister the jquery and then register another one etc. On some forums its says that i have to use a non conflict mode while others tell me just to enque it and thats it. 我唯一关心的是jquery,在某些论坛上说我必须注销jquery,然后再注册另一个,依此类推。在一些论坛上,它说我必须使用非冲突模式,而其他论坛则告诉我只是为了入队,这就是它。 what is proper practice in this case? 在这种情况下,什么是正确的做法? I am not looking for a temporary solution I would like this theme to update without issue or breaking in the future. 我不是在寻找一个临时的解决方案,我希望这个主题可以更新而不会出现问题或将来会中断。

In the case of using the non conflict method. 在使用非冲突方法的情况下。 I have created a file named foundation.js and have enqued it in the functions.php file with this code: 我创建了一个名为Foundation.js的文件,并使用以下代码将其加入到functions.php文件中:

jQuery.noConflict();
jQuery(document).ready(function($) {
    $(document).foundation();
});

Is this the right method? 这是正确的方法吗?

The jQuery library included with WordPress is set to the noConflict() mode. WordPress随附的jQuery库设置为noConflict()模式。 In noConflict() mode, the global $ shortcut for jQuery is not available. noConflict()模式下,jQuery的全局$快捷方式不可用。 So in foundation.js you can just use: 因此,在foundation.js您可以使用:

jQuery(document).ready(function ($) {
    jQuery(document).foundation();
});

check this link from the Codex 从食典中检查此链接

The documentation is sketchy, but this should be the correct way, at least it works for me: 文档是粗略的,但这应该是正确的方法,至少对我有用:

In functions.php: 在functions.php中:

function my_enqueue_foundation() {
    wp_register_script('foundation', get_template_directory_uri() . '/js/foundation.min.js','','1.1', true);
    wp_enqueue_script('foundation');
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_foundation' );

Then initialize foundation in footer.php 然后在footer.php中初始化基础

<?php wp_footer(); ?>


<script> jQuery(document).foundation(); </script>

If you followed the tutorial you linked to ( github ) you're all set. 如果您遵循链接到( github )的教程,那么一切都准备就绪 In the theme's functions.php file foundation JS and an init script are enqueued: 在主题的functions.php文件基础中,加入了JS和初始化脚本:

function awesome_theme_scripts(){
    // scripts here ...
    wp_enqueue_script( 'foundation-js', get_template_directory_uri() . '/foundation/js/foundation.min.js', array( 'jquery' ), '1', true );
    wp_enqueue_script( 'foundation-init-js', get_template_directory_uri() . '/foundation.js', array( 'jquery' ), '1', true );
    // more scripts...
}

The latter contains the noConflict code and initializes Foundation: 后者包含noConflict代码并初始化Foundation:

jQuery(document).ready(function($) {
    $(document).foundation();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM