简体   繁体   English

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

[英]List All Posts From A WordPress Site On A PHP Page

Edit:The problem is the script timeout. 编辑:问题是脚本超时。

Up to WordPress version 3.2.1 I used this code on a page called 'list.php' in the root of my site. 在WordPress 3.2.1之前的版本中,我在网站根目录中名为“ list.php”的页面上使用了此代码。 When I go to this page, permalinks to all the posts I posted on my site show up. 当我转到此页面时,将显示指向我在网站上发布的所有帖子的永久链接。

Once I installed WordPress 3.5.1 this code stopped working. 一旦我安装了WordPress 3.5.1,此代码就会停止工作。 How could we fix it? 我们该如何解决?

<?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>";
    }
?>

Did you tried using WP_Query and the call of wp-load.php at the beginning of your php file? 您是否尝试过在文件的开头使用WP_Querywp-load.php的调用? The code will look like this: 该代码将如下所示:

<?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;
?>

Where ../../....../ is the path to your wp-load.php file. 其中../../....../wp-load.php文件的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM