我正在尝试在wordpress之外的静态页面上获取最新的wordpress帖子。我正在尝试遵循代码,但它不起作用(即。我没有得到任何输出)。
<?php
$config_file = $_SERVER['DOCUMENT_ROOT'].'/wp/wp-config.php';
include($config_file);
$postlist = get_posts('numberposts=5');
foreach ($postlist as $post) : ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php endforeach; ?>
wp-config 文件仅存储这些变量以用于其他脚本。它没有定义任何wordpress函数。我相信你要找的会是这样的东西。
define('WP_USE_THEMES', false);
require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
之后,您应该能够使用wordpress功能。