【问题标题】:Show blog posts on non-wordpress site with php使用 php 在非 wordpress 网站上显示博客文章
【发布时间】:2016-12-19 05:59:50
【问题描述】:

我正在尝试使用 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='/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') 在 /home/devbh/public_html/app/design/frontend/test1/default/template/page/hpBlog.phtml 第 35 行

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

【问题讨论】:

标签: php wordpress magento


【解决方案1】:

一些示例代码应该如何工作:

<?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 配置。确保您的虚拟主机可以访问您的其他目录(从安全角度来看,这样做有点讨厌)

【讨论】:

    猜你喜欢
    • 2021-04-16
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多