title: Rerun loop after every third post? (Wordpress)
body: <p>I have a problem in my template (wordpress).
  I want to create a portfolio page which contains 3 columns and which can display posts in my portfolio page (without jumping a new page). And I need to repeat these three posts after each third post. I will assign "hidden" class to my duplicate posts and when clicking at the column, class shall set as "block".
  I have a code:</p>
  
  <pre><code>&lt;?php get_header(); ?&gt;
  &lt;section&gt; &lt;div class="container container-bazar container-gallery"&gt;&lt;?php 
  $array = array();
      $count = 0;
      $i = 0;
  $args = array(
      'posts_per_page' =&gt;  -1,
      'post_type' =&gt; 'gallery',
  );
  $gallery = new WP_Query( $args );
  if($gallery-&gt;have_posts()) :
  while($gallery-&gt;have_posts()) :
          $gallery-&gt;the_post(); ?&gt;
  &lt;div class="col-1 boxes&lt;?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?&gt;"&gt;
      &lt;div class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt;
          &lt;figure class="indent-bot"&gt;
              &lt;a href="&lt;?php the_permalink(); ?&gt;" rel="nofollow"&gt;
                  &lt;?php the_post_thumbnail(array(380,220,true)); ?&gt;
              &lt;/a&gt;
          &lt;/figure&gt;
          &lt;div class="col-1-content"&gt;
              &lt;strong class="title-3"&gt;
                  &lt;a href="&lt;?php the_permalink(); ?&gt;" rel="nofollow"&gt;
                      &lt;?php the_title(); ?&gt;
                  &lt;/a&gt;
              &lt;/strong&gt;
              &lt;div class="entry"&gt;
                  &lt;a href="&lt;?php the_permalink(); ?&gt;" rel="nofollow"&gt;
                      &lt;?php the_excerpt(); ?&gt;
                  &lt;/a&gt;
              &lt;/div&gt;&lt;!-- .entry --&gt;
          &lt;/div&gt;&lt;!-- .col-1-content--&gt;
      &lt;/div&gt;&lt;!-- .post --&gt;
  &lt;/div&gt; &lt;!-- .boxes --&gt;
  &lt;?php endwhile; ?&gt;
  &lt;?php while($gallery-&gt;have_posts()) :
  $gallery-&gt;the_post();?&gt;
  &lt;?php $imgaddr1 = get_post_meta($post-&gt;ID, 'imgaddr1', true);
  $imgaddr2 = get_post_meta($post-&gt;ID, 'imgaddr2', true);
  $imgssilka1 = get_post_meta($post-&gt;ID, 'imgssilka1', true);
  $imgssilka2 = get_post_meta($post-&gt;ID, 'imgssilka2', true);
  $namecolor1 = get_post_meta($post-&gt;ID, 'namecolor1', true);
  $namecolor2 = get_post_meta($post-&gt;ID, 'namecolor2', true);
  $numbercolor1 = get_post_meta($post-&gt;ID, 'numbercolor1', true);
  $numbercolor2 = get_post_meta($post-&gt;ID, 'numbercolor2', true); ?&gt;
  &lt;/div&gt;
          &lt;div class="full clearfix"&gt;
              &lt;div class="inner"&gt;
                  &lt;figure class="indent-bot1"&gt;
                      &lt;a href="&lt;?php the_permalink(); ?&gt;" rel="nofollow"&gt;
                          &lt;?php the_post_thumbnail(array(960,690)); ?&gt;
                      &lt;/a&gt;
                  &lt;/figure&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-md-5"&gt;
                          &lt;div class="inf-1"&gt;
                              &lt;h4&gt;Информация&lt;/h4&gt;
                          &lt;/div&gt;
                          &lt;div class="inf-2"&gt;
                              &lt;h5&gt;&lt;?php the_title(); ?&gt;&lt;/h5&gt;
                              &lt;div class="desc"&gt;
                                  &lt;?php the_excerpt(); ?&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="clearfix"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-md-7 border-left"&gt;
                          &lt;div class="inf-1"&gt;
                              &lt;h4&gt;Приложенные Цвета&lt;/h4&gt;
                          &lt;/div&gt;
                          &lt;div class="inf-2"&gt;
                              &lt;ul&gt;
                                  &lt;li class="first-child"&gt;
                                      &lt;a href="&lt;?php echo $imgssilka1; ?&gt;" class="img-block"&gt;
                                          &lt;img src="&lt;?php echo $imgaddr1; ?&gt;"&gt;
                                      &lt;/a&gt;
                                      &lt;div class="txt"&gt;
                                          &lt;strong&gt;&lt;?php echo $namecolor1; ?&gt;&lt;/strong&gt;
                                          &lt;span&gt;&lt;?php echo $numbercolor1; ?&gt;&lt;/span&gt;
                                      &lt;/div&gt;
                                  &lt;/li&gt;
                                  &lt;li class="last-child"&gt;
                                      &lt;a href="&lt;?php echo $imgssilka2; ?&gt;" class="img-block"&gt;
                                          &lt;img src="&lt;?php echo $imgaddr2; ?&gt;"&gt;
                                      &lt;/a&gt;
                                      &lt;div class="txt"&gt;
                                          &lt;strong&gt;&lt;?php echo $namecolor2; ?&gt;&lt;/strong&gt;
                                          &lt;span&gt;&lt;?php echo $numbercolor2; ?&gt;&lt;/span&gt;
                                      &lt;/div&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/div&gt;
                          &lt;div class="clearfix"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;&lt;!-- .inner --&gt;
          &lt;/div&gt;
  &lt;div class="container container-bazar container-gallery"&gt;
  &lt;?php endwhile; 
  else: 
  endif; ?&gt;
  &lt;/div&gt;&lt;!-- .container --&gt;
  &lt;/section&gt;
  &lt;?php get_footer(); ?&gt;
  </code></pre>
  
  <p>but this code displays posts sequentially. </p>