how to make the "$first_post" query work on the second loop
-
I have this custom sub category page with six loops in it for styling purposes.
The second and the fifth loops has two columns in a section with the first column has a bigger sized featured image and no excerpt and the second with a smaller featured image with excerpt diplayed.
I used to $first_post query to achive the result which works on the main category page where is have one loop for each category. Can’t get it work here, I understand it’s not the first post but tried to change current_post number but still not working.
Can anyone help me with this please.Here is my code for the second loop:
<?php rewind_posts(); $my_query = new WP_Query( array( 'category_name' => 'il belpaese', 'posts_per_page' => 2, 'post__not_in' => $do_not_duplicate ) ); ?> <section class="category-box clear"> <div class="bg-wrapper clear"> <?php while ( $my_query->have_posts() ) : $my_query->the_post(); $do_not_duplicate[] = $post->ID; ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <section class="sub-cat-post medium-left clear"> <?php $first_post = $wp_query->current_post == 2 && !is_paged() && is_archive(); ?> <?php if ( $first_post == true ) { ?> <figure class="featured-image medium-img"> <a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"> <?php the_post_thumbnail( 'category-medium' ); ?> </a> </figure> <div class="entry-title-wrapper"> <h3 class="entry-title"> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?> </a> </h3> <?php if (function_exists( 'button_excerpt_more' ) ) { echo '<span class="button-more">' . button_excerpt_more() . '</span>'; } ?> </div> <?php } else { ?> <figure class="featured-image"> <a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"> <?php the_post_thumbnail( 'category-small' ); ?> </a> </figure> <h3 class="entry-title"> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?> </a> <?php if (function_exists( '_button_excerpt_more' ) ) { echo '<span class="button-more">' . button_excerpt_more() . '</span>'; } ?> </h3> <?php if ( has_excerpt( $post->ID ) ) { echo '<div class="deck">'; echo '<p>' . excerpt(35) . '</p>'; echo '</div><!-- .deck -->'; } ?> <?php } ?> </section> </article><!-- #post-## --> <?php endwhile; ?> </div> </section>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘how to make the "$first_post" query work on the second loop’ is closed to new replies.