我可以在functions.php中包含php吗? - Wordpress

时间:2015-02-27 13:56:49

标签: php wordpress include

当我在WP中发布新帖子时,我需要调用自定义php脚本。此功能有效,但不包含。它不包括在内。它可以工作还是有其他方法在functios.php中包含php文件?

function new_post_caller( $ID, $post )  {

    include( get_template_directory() . 'call_new_post.php?ID='.$ID.'' );

}

add_action( 'publish_mypost', 'new_post_caller', 10, 2 );

3 个答案:

答案 0 :(得分:1)

函数include()只包含用于执行的php / html文件,没有GET或POST参数。

答案 1 :(得分:1)

如果你想包含脚本并将参数传递给他,你可以在包含脚本和使用构造中创建函数,如下所示:

要包含的一些脚本(file.php):

function some_function ($id) {
 //some code, using $id
}

并调用file.php并传递参数:

include('file.php'); 
some_function(23);

函数include()只是将包含文件的代码添加到发起函数的文件中 http://php.net/manual/en/function.include.php

答案 2 :(得分:0)

使用include( get_template_directory() . '/filetoinclude.php' ); 它会起作用。