0

我正在尝试在 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; ?>
4

1 回答 1

0

wp-config 文件仅存储这些变量以供其他脚本使用。它没有定义任何 wordpress 功能。我相信你正在寻找的是这样的。

    define('WP_USE_THEMES', false);
  require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');

之后,您应该能够使用 wordpress 功能。

于 2012-08-15T22:38:44.543 回答