在PHP页面上列出WordPress站点的所有帖子


List All Posts From A WordPress Site On A PHP Page

编辑:问题是脚本超时。

直到WordPress版本3.2.1,我在我的网站根目录下的一个名为"list.php"的页面上使用了这段代码。当我进入这个页面时,我在我的网站上发布的所有帖子的永久链接都会显示出来。

一旦我安装了WordPress 3.5.1,这个代码就停止工作了。我们怎样才能解决这个问题?

<?php
    require_once('wp-config.php');
    require_once('wp-includes/wp-db.php');
    global $post;
    $myposts = get_posts('numberposts=-1&offset=1');
    foreach($myposts as $post){
        echo trim(the_permalink())."<br>";
    }
?>

您是否尝试在php文件的开头使用WP_Querywp-load.php的调用?代码看起来像这样:

<?php

header('Content-Type: text/html; charset: UTF-8');
require( '../../../../wp-load.php' );
$my_query = new WP_Query('numberposts=-1&offset=1'); 

if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); 
echo trim(the_permalink())."<br>";
endwhile;
endif;
?>

其中../../....../wp-load.php文件的路径