这是对query_posts() 仅用于修改页面的主查询。此外,即使您将代码段更改为使用get_posts(), 您的模板标签(例如。the_excerpt()) 不会像get_posts() 不是一种在帖子中循环的方法,它只是返回一个帖子数组。
你想要的是WP_Query. 将第一行代码更改为:
$args = array(
\'post_type\' => \'page\',
\'post__in\' => array(3,5,7)
);
$my_three_posts = new WP_Query( $args );
while ($my_three_posts -> have_posts()) : $my_three_posts -> the_post();
...