Placing a div or img in between a post array using WP Query [closed]

You can add your div every after 2 posts like this.

  <?php $count = 1; // add this before loop ?> 

 <?php
  // add this inside the loop
 if ($count % 3 == 0) : 
                    echo 'YOUR IMAGE DIV HERE';
 endif; $count++; ?>

So, it will be something like this.

        <?php $args = array( 'post_type' => 'galleries');
                    $queryone = new WP_Query( $args ); 
                    $count = 1; 
                 while ($queryone -> have_posts()) : $queryone -> the_post(); ?>
    <?php if ($count % 3 == 0) : 
                        echo 'YOUR IMAGE DIV HERE';
     endif; $count++; ?>
                    <section class="feature-third">
                    <a href="https://wordpress.stackexchange.com/questions/271169/<?php echo get_permalink( $ID ); ?>" title="<?php the_title( ); ?>">
                    <div class="feature-captions"><?php $current_cat_id = the_category_ID(false); echo '<p class="category-link">' . get_cat_name($current_cat_id) . '</p>';  ?><h2><?php echo get_the_title( $post->ID ); ?> </h2><?php if( get_field('subtitle') ): ?><p><?php the_field('subtitle'); ?></p><?php endif; ?></div>
                <?php the_post_thumbnail('full'); ?>
            </a>
        </section>
    <?php endwhile; ?>

Leave a Comment