Quantcast
Channel: User Michael - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 44

Answer by Michael for Show 5 posts and than 3 posts offset with pagination

$
0
0

under settings - reading, set 'blog pages show at most' to 8

then use conditional statements based on the current post number in the loop;

<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?><?php //conditionally outputting the opening tags for the first sectionif( $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 tagsif( $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 sectionif( $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 tagsif( $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; ?>

it might look more complicated, but you don't need to worry about the pagination.the code will need to be adapted if you want to show the archive links even if there are no more posts.


Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>