简体   繁体   English

将基础5包含在wordpress主题中的正确方法是什么?

[英]what is correct way to include foundation 5 in a wordpress theme?

I'm trying to create a wordpress theme from my Foundation website. 我正在尝试从Foundation网站创建一个wordpress主题。

what is the correct way to enqueue the javascript files I need in functions.php? 将我需要的javascript文件排入functions.php的正确方法是什么? I found many tutorial online but none is 100% 我在网上找到了很多教程,但都不是100%

this is the way I did but for some reason my top bar toggle doesn't work, I assume I'm not including jquery in the correct way. 这是我的方法,但是由于某种原因,我的顶部栏切换不起作用,我认为我没有以正确的方式包含jquery。

I have to say that I don't know anything about PHP and I'm trying to find examples that would work in my case with no luck.. 我不得不说,我对PHP一无所知,我试图找到适合我的情况的示例,但没有运气。

<?php

function devocean_script()  
{  
    //register scripts for our theme  
    wp_deregister_script('jquery');

    wp_register_script('jquery',  get_template_directory_uri() . '/js/vendor/jquery.js', 
    false );
    wp_register_script('foundation-mod',  get_template_directory_uri() . '/js/modernizer.js', 
false );  
wp_register_script('foundation-main', get_template_directory_uri() . '/js/foundation.min.js', 
    true );  



//enqueue scripts for our theme
wp_enqueue_script( 'foundation-mod' );
wp_enqueue_script( 'jquery');  
wp_enqueue_script( 'foundation-main' );
}  
add_action( 'wp_enqueue_scripts', 'devocean_script' );  

?>

It would be great if somwone could give me a hint.. I'm really stucked here and need to keep moving.. 如果somwone可以给我提示,那就太好了。.我真的被困在这里,需要继续前进。

thanks a lot for your help 非常感谢你的帮助

Before you use foundation 5 with wordpress,please note the following. 在将Foundation 5与wordpress一起使用之前,请注意以下几点。

  1. modernizr should load on wp-head. modernizr应该在wp-head上加载。

 wp_enqueue_script( 'modernizr', get_template_directory_uri() .'/js/vendor/modernizr.js', array(), '', false ); 
or through CDN network like this 或像这样通过CDN网络

 wp_enqueue_script( 'modernizr', '//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js', array(), '', false ); 

  1. Load jquery at footer 在页脚加载jQuery

  function jqloading() { wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'); wp_enqueue_script('jquery'); } add_action('wp_footer','jqloading'); 

  1. enque foundation js and foundation css files 封装基础js和基础css文件

 wp_enqueue_script( 'foundation-js', 'https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/foundation.min.js', array('jquery'), '1.0', true ); wp_enqueue_style( 'foundation-style', get_template_directory_uri() .'/css/foundation.min.css' ); 

  1. Make sure that foundation is initialised by adding this code in footer.ph 通过在footer.ph中添加此代码来确保基础已初始化

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

Have you tried it without deregistering jquery? 您是否尝试过而不注销jquery?

Plus you should have jquery loaded in the footer by passing true as the last argument to the wp_reqister_script function. 另外,应该通过将true作为最后一个参数传递给wp_reqister_script函数,在页脚中加载jquery。 Of course this only works if you have the call to wp_footer in the right place in your theme. 当然,仅当您在主题的正确位置调用了wp_footer时, wp_footer

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

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