我只是想把第一篇文章排除在功能帖之外,这里是功能帖的代码。
<ul class="headlines">
<?php $recent = new WP_Query(array('posts_per_page' => get_option('gd_right_now') )); while($recent->have_posts()) : $recent->the_post();?>
<li>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('small-thumb'); ?></a>
<div class="headlines-text">
<span class="date-cat"><?php the_time(get_option('date_format')); ?> | </span><ul class="headlines-cat"><?php $category = get_the_category(); echo esc_html( $category[0]->cat_name ); ?></ul>
<p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p>
</div><!--headlines-text-->
</li>
<?php endwhile; ?>
</ul>
只要你拉的选项没有设置为"-1",你就可以使用 "offset "参数。
new WP_Query(
array(
'posts_per_page' => get_option('gd_right_now'),
'offset' => 1
)
);
另一种方法,如果你确实设置了"-1",则可以获取最近的帖子的ID,并在查询中排除该帖子。
$post_to_exclude = '';
$my_posts = get_posts( array(
'numberposts' => 1,
) );
foreach ($my_posts as $post) {
$post_to_exclude = $post->ID;
}
new WP_Query(
array(
'posts_per_page' => get_option('gd_right_now'),
'post__not_in' => $post_to_exclude
)
);