包含几个js文件的php文件

时间:2015-03-31 10:37:53

标签: javascript php wordpress

我有一个小问题。我上传了3个文件到我的服务器。 1个php文件和2个js文件。 PHP文件引用了这2个JS文件。我需要在wordpress的页面上运行这些文件。我试图安装EXEC PHP插件,我写了

include './online/demo_iframe.php';
wp_enqueue_script( "jquery.ba-postmessage", "./online/jquery.ba-postmessage.js", false, false ); 
wp_enqueue_script( "jquery.min", "./online/jquery.min.js", false, false );

但这不起作用。所以,问题是,我知道如何运行php文件,使用" include"但我不知道如何连接这个PHP文件与我的2个js文件。谢谢。

1 个答案:

答案 0 :(得分:0)

出现网址路径问题,请尝试使用文件的完整(非相对)路径:

<?php
//For PHP include, use full path to your file, e.g. /var/www/example.com/wp-content/themes/etc/etc
include 'full_path_to_your_php_file/online/demo_iframe.php';
//For JS scripts, use bloginfo('url') to point to your files
wp_enqueue_script( "jquery.ba-postmessage", bloginfo('url')."/path_to_your_theme_file/online/jquery.ba-postmessage.js", false, false ); 
wp_enqueue_script( "jquery.min", bloginfo('url')."/path_to_your_theme_file/online/jquery.min.js", false, false );