基于Johannes的代码,但使用post__not_in
参数:
/* Secondary query using WP_Query */
$wpse63027_posts = new WP_Query( array(
\'category_name\' => \'MyCatName\',
\'posts_per_page\' => -1,
\'post__not_in\' => array( get_queried_object_id() ), // Exclude current post ID (works outside the loop)
) );
然后,您可以循环浏览新帖子:
if ( $wpse63027_posts->have_posts() )
{
while( $wpse63027_posts->have_posts() )
{
$wpse63027_posts->the_post();
// Now do everything you want with the default API calls
// Example
the_title( \'<h2>\', \'</h2>\', true );
the_content();
}
}
WP_Query » Post_*/Page_Parameters