Posts with a loop that has two different formats
-
I’m loading paged posts with a loop that has two different formats. I use a counter to determine if the post is the first post. If it is then it is formatted this way, if else (not first post) then format it another way.
My code:
<?php // set up or arguments for our custom query $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query_args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'paged' => $paged ); // create a new instance of WP_Query $the_query = new WP_Query( $query_args ); ?> <?php if ( $the_query->have_posts() ) : $counter = 1; while ( $the_query->have_posts() ) : $the_query->the_post(); if( $counter == 1 ) { ?> <article id ="featured"> Format A </article> <?php } else {?> <article id="non-featured"> Format B </article> <?php } $counter++; endwhile; endif; ?>
When user loads more posts (since this is paged) I need the rest of the paged posts to be in format B. How can I do this? Right now, every first post on the page loads in format A (because of the counter).
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Posts with a loop that has two different formats’ is closed to new replies.