编辑:问题是脚本超时。
在 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_Query
并调用 wp-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
文件的路径。
关于php - 在 PHP 页面上列出 WordPress 网站的所有帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16796188/