Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何向函数中的变量添加/要求完整的php文件_Php_Wordpress_Function_Variables_Require - Fatal编程技术网

我如何向函数中的变量添加/要求完整的php文件

我如何向函数中的变量添加/要求完整的php文件,php,wordpress,function,variables,require,Php,Wordpress,Function,Variables,Require,我正在Wordpress中构建,并使用jQuery.load加载了一些内容 $item = '<h2>'. the_title() .'</h2><div>'. the_content() .'</div>'; //$item = include 'myrequire.php'; This doesn't seem to work. $item=''。_title()。_content(); //$item=包括“myrequire.php”;

我正在Wordpress中构建,并使用jQuery.load加载了一些内容

$item = '<h2>'. the_title() .'</h2><div>'. the_content() .'</div>';
//$item = include 'myrequire.php'; This doesn't seem to work. 
$item=''。_title()。_content();
//$item=包括“myrequire.php”;这似乎不起作用。
我想知道如何使php变量$item加载一个php文件,这样我就可以保持functions.php整洁,并可以像这样编写文件:

<h2><?php the_title(); ?><h2> 

。。。这有意义吗

谢谢

我遵循了本教程:

以下是完整的片段:

function getArchives($count,$offset){
query_posts('posts_per_page='.$count.'&offset='.$offset);

$posts = array();

if(have_posts()) : while(have_posts()) : the_post();    


    $item = '<h2>'. the_title() .'</h2><div>'. the_content() .'</div>';
    //$item = include 'myrequire.php';

array_push($posts,$item); endwhile; endif;

return $posts;
};
函数getArchives($count,$offset){ 查询发布('posts\u per\u page='.$count.&offset='.$offset'); $posts=array(); if(have_posts()):while(have_posts()):the_post(); $item=''.the_title()'。the_content()'; //$item=包括“myrequire.php”; 数组_push($posts,$item);endwhile;endif; 返回$员额; };
include执行文件,您需要文件获取内容

$var=file_get_contents($filename);
你也可以用get_template_part的wordpress方式来完成,但这取决于你想做什么。我会看看法典


您想知道php文件的内容吗?

谢谢,这看起来应该是正确的,但不幸的是,我的代码无法加载该文件。还有其他一些问题(在上面的工作示例中,它似乎忽略了html标记。如果我抓取它加载的外部文件:/),可能是路径问题。在这种情况下,请尝试文件的绝对路径。或者,这可能是一个权限问题,在这种情况下,请尝试使用chmod 777访问该文件