基于几个不同的答案SPECIAL 幸亏EAMann\'s相似answer - 这是我遵循的方法
使用new WP_Query
而不是query_posts
对于此页定义查询变量($main_query
) 作为全球性的查询临时数组($temp_featured
) 我的特色帖子创建一个仅具有“$temp\\u featured”ID的数组。注意EAMann使用wp_list_pluck 功能
执行页面的主查询($main_query
) 使用参数排除#4中检索到的ID李>总而言之,事情就是这样发生的:
global $main_query;
$temp_featured = get_posts(
array(
\'post_type\' => \'custom_post\',
\'custom_post-category\' => \'featured-cat\',
\'posts_per_page\' => 2)
);
$featured_ids = wp_list_pluck( $temp_featured, \'ID\' );
$query_args = array(
\'post_type\' => \'custom_post\',
\'posts_per_page\' => $per_page,
\'paged\' => $current_page,
\'post__not_in\' => $featured_ids
);
$main_query = new WP_query ($query_args);
//displaying the two featured posts with their own query
$featured = new WP_query( array(
\'post_type\' => \'custom_post\',
\'custom_post-category\' => \'featured-cat\',
\'posts_per_page\' => 2)
);
while ($featured->have_posts ()) : $featured->the_post();
the_title();
the_excerpt();
endwhile;
//displaying the full query of the page
if ($main_query->have_posts ()) :
while ($main_query->have_posts ()) : $main_query->the_post();
the_title();
the_excerpt();
endwhile;
endif;
我希望这对任何人都有帮助-如果您有进一步的想法或疑问,请编辑/评论或与我联系。