-1
有人为我做了这段代码,以json格式加载文章,但它只加载了10篇最新文章。我如何将其更改为加载所有帖子?为什么这段代码只加载10条最新帖子?
我试过?page = 2但它不起作用。
代码
<?php
header("Content-type: application/json");
include ('wp-load.php');
$loop = new WP_Query(array('post_status' => 'publish', 'post_type' => 'post'));
if($loop->have_posts()) : while($loop->have_posts()) : $loop->the_post();
$posts[] = array(
'id' => $post->ID,
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'guid' => $post->guid,
'image' => (has_post_thumbnail() ? get_the_post_thumbnail_url() : ''),
'cats' => the_category_ID(false),
'post_date' => $post->post_date,
);
endwhile; endif;
echo json_encode($posts);
?>
页取得参数没有传递到WordPress的查询:'$循环=新WP_Query(阵列(“post_status” =>'publish','post_type'=>'post'));' – jedifans
那我该怎么办?我希望在一个页面中显示所有帖子 – hesam