如何有一个查询,但在两个单独的HTML块中的页面上两次使用它以显示不同的帖子

问题描述 投票:0回答:1

在我的主页上,我目前在顶部有一个特色帖子。然后,在页面后期,我使用偏移1显示了接下来的四个最新帖子,以不显示特色帖子。 我目前使用以下代码使用两个查询;

<?php $query = new WP_Query( array( 'post_type' => array('post'), 'posts_per_page' => 1 ) ); ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?> /*Show post info here*/ <?php endwhile; ?>

然后,我在页面下方还有第二个全新的查询,做同样的事情,但请致电接下来的4个帖子。
<?php $query = new WP_Query( array(
        'post_type' => array('post'),
        'posts_per_page' => 4,
            'offset' => 1,
    ) );
    ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
   /*Show post info here*/
<?php endwhile; ?>

有一种方法可以进行一次查询,但仍将结果输出到两个单独的HTML块?

您可以使用WordPress使用唯一的查询

get_posts()
wordpress posts
1个回答
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.