如果要在列表中显示3篇文章,可以遵循以下模式:
<?php
$args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DSC\',
\'posts_per_page\' => 3
);
$post_query = new WP_Query($args);
if($post_query->have_posts()): while($post_query->have_posts()):$post_query->the_post();
?>
<div>
<h1> <?php the_title(); ?> </h1>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
endif;
?>
现在,如果要在另一个部分中显示其余的帖子,但要排除前3篇帖子,请使用偏移量。以下是示例:
<?php
$args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DSC\',
\'posts_per_page\' => -1, // will show unlimited posts
\'offset\' => 3
);
$post_query = new WP_Query($args);
if($post_query->have_posts()): while($post_query->have_posts()):$post_query->the_post();
?>
<div>
<h1> <?php the_title(); ?> </h1>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
endif;
?>
您需要根据需要编辑代码。希望这对你有帮助。