我在Wordpress中構建並且有一些使用jQuery.load加載的內容。我要添加/需要一個完整的php文件到一個函數中的變量
$item = '<h2>'. the_title() .'</h2><div>'. the_content() .'</div>';
//$item = include 'myrequire.php'; This doesn't seem to work.
我想知道如何使PHP變量$項目加載一個PHP文件 - 這樣我就可以不斷的functions.php整潔,可以只寫如文件:
<h2><?php the_title(); ?><h2>
。 .. 那有意義嗎?
謝謝!
我跟着這個教程: http://tomsbigbox.com/wordpress-load-more-posts-on-page-scroll/
這裏是完整的片段:
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;
};
謝謝,這看起來應該是正確的,但不幸的是我的代碼無法加載文件。還有其他事情正在進行(它似乎忽略了我的工作示例中的html標籤..如果我抓住外部文件加載:/) –
colin
也許這是路徑問題。在這種情況下,請嘗試文件的絕對路徑。或者它可能是一個權限問題,並在這種情況下嘗試chmod 777該文件 –