但是它向我显示了以下错误 Fatal error: Call to unde-6ren">
gpt4 book ai didi

php - 在非 wordpress php 页面之外显示 wordpress 帖子

转载 作者:行者123 更新时间:2023-12-02 05:25:39 26 4
gpt4 key购买 nike

我需要在非 wordpress php 页面中显示 wordpress 博客文章。我试过下面的代码。

<?php
// Include WordPress
define('WP_USE_THEMES', false);
//exact path for wp-load.php.
// This file is kept in the root of wordpress install
require('http://test.com/wordpress/blog/wp-load.php');
//Query wordpress for latest 4 posts
query_posts('showposts=5');
?>
<?php while (have_posts ()): the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>

<?php endwhile; ?>

但是它向我显示了以下错误

Fatal error: Call to undefined function query_posts()

如何解决这个问题?

最佳答案

请查看代码中的以下行

require('http://test.com/wordpress/blog/wp-load.php');

在 require 函数中,您应该使用相对路径或物理路径。您不应包含该网址。

关于php - 在非 wordpress php 页面之外显示 wordpress 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13122116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com