我在侧边栏的一个小部件中列出了我最近的两篇帖子。当我在单间查看这些帖子时。php,我希望将该帖子从列表中排除,而是按顺序显示下一篇帖子。
仅有一个的php如下所示:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
[Content]
<?php endwhile; else : ?>
[If no post is found]
<?php endif; ?>
下面是PHP小部件中的代码:<?php $the_query = new WP_Query( \'showposts=2\' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
[Recent posts]
<?php endwhile;?>
Edit - the solution:
<?php global $post; $args = array(\'showposts\' => 2, \'post__not_in\' => array( $post->ID )); query_posts( $args ); if (have_posts()) : while (have_posts()) : the_post(); ?>
[Recent posts]
<?php endwhile; wp_reset_query(); endif; ?>