Breaking loop then restarting
-
I’ve got a custom post type called “Projects” displayed in a grid on my homepage. I’d like to insert three different text blocks within this grid: one before the loop starts, one after the 3rd post, one after the 6th post.
The content for these blocks are served up via an ACF field: ‘intro_text_1’, ‘intro_text_2’, and ‘intro_text_3’.
I got the text block before the loop to work, but I have no idea how to insert the other two.
I’ve read that adding a counter could be helpful here, but I’m really not sure how to correctly implement it.
I’m currently developing locally, so I don’t have a URL to share.
Here is the code I’m using:
<div class="projects-list" id="projects"> <div class="project-item"><?php the_field('intro_text_1'); ?></div> <?php $args = array( 'post_type' => 'project', 'posts_per_page' => 60 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="project-item"><a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail( 'homepage-thumb' ); ?> <div class="overlay"><div class="caption"> <h2><?php the_title(); ?></h2> <?php $terms = get_the_terms($post->ID, 'work_type'); if ($terms) { $terms = array_map( function($obj) { return $obj->name; }, $terms ); echo '<div class="project-work-type">(' . implode(', ', $terms) . ')</div>'; } ?> </div> </div></div> </a> <?php endwhile;?> </div>
I’ve tried various ways of including a counter, but none have worked, likely because I’m not sure where to correctly place them.
Any help would be much appreciated!
- The topic ‘Breaking loop then restarting’ is closed to new replies.