在下面settings - reading, 将“博客页面最多显示”设置为8
然后根据循环中的当前post编号使用条件语句;
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
//conditionally outputting the opening tags for the first section
if( $wp_query->current_post == 0 ) { ?>
<div class="posts-wrap">
<div class="grid">
<?php }
//conditionally outputting the template part
if( $wp_query->current_post <= 4 ) get_template_part(\'template-parts/content\', get_post_format());
//conditionally outputting the closing tags
if( $wp_query->current_post == 4 || $wp_query->current_post < 4 && $wp_query->current_post == $wp_query->post_count-1 ) { ?>
</div>
</div>
<?php }
//conditionally outputting the opening tags for the second section
if( $wp_query->current_post == 5 ) { ?>
<div class="more">
<div class="all-by-date">
<h2>Browse Archives</h2>
<ul>
<?php wp_get_archives(array(\'type\' => \'monthly\', \'limit\' => 12)); ?>
</ul>
</div>
<div class="posts-wrap">
<?php }
//conditionally outputting the template part
if( $wp_query->current_post > 4 ) get_template_part(\'template-parts/content\', \'single-preview\');
?>
<?php //conditionally outputting the closing tags
if( $wp_query->current_post == 7 || $wp_query->current_post > 4 && $wp_query->current_post == $wp_query->post_count-1 ) { ?>
</div>
</div>
<?php } ?>
<?php endwhile; ?>
<?php numbered_pagination_links(); ?>
<?php endif; ?>
它可能看起来更复杂,但您不需要担心分页。如果您想显示存档链接,即使没有更多帖子,也需要修改代码。