我試圖在不使用WordPress的網站的主頁上顯示最近的博客帖子,使用php。用php顯示非WordPress網站上的博客文章
這是我的代碼:
<?php require('../../../../../../../blog/wp-blog-header.php');
?>
<?php
$args = array('numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts($args);
echo '<ul id="latest_posts">';
foreach ($postslist as $post) : setup_postdata($post); ?>
<li><strong><?php the_date(); ?></strong><br />
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"> <?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
但我發現了這個錯誤:
Fatal error: require(): Failed opening required '../../../../../../../blog/wp-blog-header.php' (include_path='/home/devbh/public_html/app/code/local:/home/devbh/public_html/app/code/community:/home/devbh/public_html/app/code/core:/home/devbh/public_html/lib:.:/usr/lib/php:/usr/local/lib/php') in /home/devbh/public_html/app/design/frontend/test1/default/template/page/hpBlog.phtml on line 35
我已確認的文件路徑是正確的,這樣不應該成爲問題,但真的不能想到它會是什麼?有任何想法嗎?
閱讀[這裏](https://wordpress.org/support/topic/integrating-wp-in-external-php -pages) –
不能使用[xml-rpc](https://codex.wordpress.org/XML-RPC)? –