使用php在非wordpress网站上显示博客文章

时间:2016-08-12 09:15:27

标签: php wordpress magento

我正在尝试使用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> 

但是我收到了这个错误:

  

致命错误:require():需要打开失败   '../../../../../../../blog/wp-blog-header.php'   (include_path中='/家庭/ devbh /的public_html /应用/代码/地方:/家庭/ devbh /的public_html /应用/代码/社区:/家庭/ devbh /的public_html /应用/代码/核心:/家庭/ devbh /的public_html / LIB:。:/ usr / lib中/ PHP:在/ usr / local / lib目录/ PHP的“)   在   /home/devbh/public_html/app/design/frontend/test1/default/template/page/hpBlog.phtml   第35行

我已经确定文件路径是正确的,所以不应该是问题,但不能真正想到它可能是什么?有什么想法吗?

1 个答案:

答案 0 :(得分:0)

一些示例代码如何工作:

<?php
// those two lines at the very top
define('WP_USE_THEMES', false);
require('/path/to/your/wordpress/wp-load.php');

// ... rest of your code like for example ...

query_posts('showposts=1');
while (have_posts()): the_post(); ?>

<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Read more...</a></p>

<?php endwhile; ?>

以下是一篇文章,其中包含更多细节:

https://wordpress.org/support/topic/display-wordpress-content-outside-of-your-blog-corvid-works

如果您的错误仍然存​​在,并且您的站点都在不同的虚拟主机上运行,​​请检查您的apache配置。确保您的vhost可以访问您的其他目录(从安全角度来看,这样做很讨厌)

相关问题