我有一个部分,我呼吁各地的网站在不同的点。此部分仅显示最新帖子。
看起来是这样的:
<?php
$args = array(
\'posts_per_page\' => 1,
\'order\' => \'desc\'
);
query_posts($args);
if ( have_posts() ) :
while ( have_posts() ) : the_post();
if (has_post_thumbnail( $post->ID ) ){
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'home-news-thumbnail\' );
}
?>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php echo get_the_title(); ?></h3></a>
<?php if(!empty($featured_image)): ?>
<a href="<?php echo get_the_permalink(); ?>">
<img src="<?php echo $featured_image[0]; ?>" alt="" width="250" class="pull-left">
</a>
<?php endif; ?>
<p>
<?php echo get_the_excerpt(); ?>
</p>
<a href="<?php echo get_the_permalink(); ?>" class="btn btn-brand-dark">more</a>
<div class="clearfix"></div>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
在我“粘贴”帖子之前,这一切都很好。然后我得到2个帖子,而不是1个。如何修改所有查询以便posts_per_page
是否有所需的帖子数量,无论帖子是否粘帖?
在上面的例子中,我现在得到2 帖子(尽管要求1),但我想要最新的帖子,不管那是不是一篇粘滞的帖子。
我知道ignore_sticky_posts
参数,但这将忽略粘性帖子,我不想这样做。如果有一个粘帖,它应该是第一个。