Loop: Multiple articles wrapped in a div
-
I have been struggling with making this work:
I’d like to have my posts wrapped in a div every 4 posts / and every 5th post would live in his own wrap, so something like that:*<div class="section"> <post></post> <div> <div class="section"> <post></post> <post></post> <post></post> <post></post> <div> <div class="section"> <post></post> <div> <div class="section"> <post></post> <post></post> <post></post> <post></post> <div> .....* ------------------- So far i succeed to wrap each 4 post into a div but i cannot figure out how to show the 5th one in his own div (full width) Here is my loop so far, any help would be greatly appreciated <3: <?php $i = 0; $postcount = 0; $wrap_div = "<div class='section ' id='section-<?php the_ID(); ?>'>"; if ( have_posts() ) { $total_posts = $wp_query->post_count; echo $wrap_div; while ( have_posts() ) { the_post(); $postcount++;?> <div class="square-lp <?php if($postcount % 1 == 0) echo " multiple5"; ?>" style="background-image:url(<?php the_field('image-background'); ?>)"> <?php the_title(); ?> </div> <?php the_field("description-full"); ?> <?php the_field("description"); </div> <?php if ( $i % 4 == 0 && $i != 1 && ( $i + 1 ) != $total_posts ) { echo '</div>' . $wrap_div; } $i ++; } // end while // Close the $wrap_div echo '</div>'; } // end if ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Loop: Multiple articles wrapped in a div’ is closed to new replies.