我正在尝试获取并显示5篇特色帖子。为了实现这一目标,我抵消了最近发表的5篇文章。我已经成功地获取了帖子的id和图片,但我无法获取每个帖子的描述。
我尝试了下面的代码,但它只给了我1个帖子描述,而不是全部5个。
$my_posts = get_posts(array(\'numberposts\' => 5,
\'offset\' => 5,
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\'));
foreach($my_posts as $post) {
$data[] =
array(
"id" => $post->ID,
"title" => $post->post_title,
"image" => get_the_post_thumbnail($post->ID),
// "content" =>$post[\'post_excerpt\']
"content" => apply_filters(\'the_content\', $post->post_content)
);
}
SO网友:Rob
像这样的事情应该会让你接近(未经测试):
<?php
foreach($my_posts as $post){
$thisPostId = $post->ID;
$thisPost = $get_post($thisPostId);
$thisPostTitle = apply_filters(\'the_title\', $thisPost->post_title);
$thisPostThumbnail = get_the_post_thumbnail($thisPost);
$thisPostContent = apply_filters(\'the_excerpt\', $thisPost->post_excerpt);
$data[] = array(
"id" => $thisPost,
"title" => $thisPostTitle,
"image" => $thisPostThumbnail,
"content" => $thisPostContent
);
}
?>