php – How to display posts (see attachment) wordpress?

Question:

I created an arbitrary post type, I display them in three columns in the template file. I need to make sure that after a series of columnar records the same records are displayed three records but with different criteria. And so every time for each row. Those duplicate entries under the row will be hidden via display: none b and called on click. You can see how it works at: http://www.staron.com/staron/eng/contents/exhibition/list.do

At the moment, I have the following code for the template (but it displays records in three columns, but how can I insert the same records after each row that I cannot figure out in the row):

<div class="container">

<?php 
    $count = 0;
    $i = 0;
    $args = array(
        'posts_per_page' =>  -1,
        'post_type' => 'gallery',
    );
    $gallery = new WP_Query( $args );
    $arr = $gallery->have_posts();
    if($gallery->have_posts()) :
    while($gallery->have_posts()) :
            $gallery->the_post(); 
?>
            <div class="col-1 boxes<?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?>">
                <div class="post" id="post-<?php the_ID(); ?>">
                    <figure class="indent-bot">
                        <a href="<?php the_permalink(); ?>">
                            <?php the_post_thumbnail(array(380,220,true)); ?>
                        </a>
                    </figure>
                    <div class="col-1-content">
                        <strong class="title-3">
                            <a href="<?php the_permalink(); ?>">
                                <?php the_title(); ?>
                            </a>
                        </strong>
                        <div class="entry">
                            <a href="<?php the_permalink(); ?>">
                                <?php the_excerpt(); ?>
                            </a>
                        </div><!-- .entry -->
                    </div><!-- .col-1-content-->
                </div><!-- .post -->
            </div><!-- .boxes -->

        <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>

Answer:

You can add the required content to a temporary variable, and then display its contents in the right place:

<?php 
    $count = 0;
    $i = 0;
    $args = array(
        'posts_per_page' =>  -1,
        'post_type' => 'gallery',
    );
    $gallery = new WP_Query( $args );
    $arr = $gallery->have_posts();
    $hidden_content = '';
    if($gallery->have_posts()) :
    while($gallery->have_posts()) :
            $gallery->the_post();
            $hidden_content .= '<h1 class="post-title">' . get_the_title() . '</h1><div class="post-excerpt">' . get_the_excerpt() . '</div>';
?>
            <div class="col-1 boxes<?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?>">
                <div class="post" id="post-<?php the_ID(); ?>">
                    <figure class="indent-bot">
                        <a href="<?php the_permalink(); ?>">
                            <?php the_post_thumbnail(array(380,220,true)); ?>
                        </a>
                    </figure>
                    <div class="col-1-content">
                        <strong class="title-3">
                            <a href="<?php the_permalink(); ?>">
                                <?php the_title(); ?>
                            </a>
                        </strong>
                        <div class="entry">
                            <a href="<?php the_permalink(); ?>">
                                <?php the_excerpt(); ?>
                            </a>
                        </div><!-- .entry -->
                    </div><!-- .col-1-content-->
                </div><!-- .post -->
            </div><!-- .boxes -->
        <?php
            if( $count%3 == 0 ) {
                echo $hidden_content;
                $hidden_content = '';
            }
        ?>

        <?php endwhile; ?>
    <?php
        if( !empty($hidden_content) ) {
            echo $hidden_content;
        }
    ?>
    <?php else : ?>
    <?php endif; ?>
Scroll to Top