Insert static blocks into a PHP loop

I am trying to insert 2 static divs inside a PHP loop , specifically one at the very beginning of the loop and one at the very end.

These 2 divs should appear in the appropriate parent .row, which is currently wrapping every 3 DIVs. How can i do this?

EDIT Here is an image to describe what I need, pink blocks is a manual insertion of a div that will have different content for the blue divs. These blue divs are just WP posts:

enter image description here

Here is my PHP, currently it creates 4 columns in the first and last rows, where there should be only 3 columns:

<?php static $c=1;
      $subs = new WP_Query( array( 'post_parent' => 14, 'post_type' => 'page' ));
      if( $subs->have_posts() ) : while( $subs->have_posts() ) : $subs->the_post(); ?>

           <?php if (($c % 3) === 1) {
             // This creates part of the wrapper .row div
             echo "<div class='row'>";
           } ?>

           <?php 
           if ($c == 1) {?>
             <div class="col_4 card bar">
              first card that is manually inserted with different content
             </div>
           <?php } ?>

              <a href="<?php the_permalink(); ?>" class="col_4 card bar no-pad <?php if($c % 3 == 0) { echo 'last'; } ?>">
                 <?php if ( has_post_thumbnail() ) {?>
                 <div class="feature-image c-1">
                       <?php the_post_thumbnail('medium'); ?>
                 </div>
                 <?php } ?>
                 <div class="excerpt-wrap">
                    This is a post from within Wordpress
                 </div>
              </a>

           <?php if ($c == 6) {?>
                <div class="col_4 card bar">
                 Last card that is manually inserted with different content
                </div>
           <?php } ?>

           <?php if (($c % 4) === 3) {
             echo "</div>";
           }?>
     <?php $c++; endwhile; endif; wp_reset_postdata(); ?>

EDIT This is the HTML structure that I would like to achieve:

<!-- very first row -->
<div class="row">
  <!-- This is a static block followed by the very first two worpdress posts-->
  <div class="static-block"></div>

  <a href="#" class="wp-post"></a>
  <a href="#" class="wp-post"></a>
</div>

<!-- I could have 3 or 30 wordpress posts repeating this format -->
<div class="row">
  <a href="#" class="wp-post"></a>
  <a href="#" class="wp-post"></a>
  <a href="#" class="wp-post"></a>
</div>

<!-- very last row -->
<div class="row">
  <!-- These are the very two worpdress posts followed by a static block -->
  <a href="#" class="wp-post"></a>
  <a href="#" class="wp-post"></a>

  <div class="static-block"></div>
</div>
+4
2
<?php
    $c = 1;
    $subs = new WP_Query(array('post_parent' => 14, 'post_type' => 'page'));
    if ($subs->have_posts()) :
    ?>
        <div class='row'>
            <?php 
                while ($subs->have_posts()) : $subs->the_post();
                if (($c % 3) == 0 || $c == 3):
            ?>
        </div><div class='row'>
        <?php
                endif;
        ?>
        <?php
            if ($c == 1):
        ?>
            <div class="col_4 card bar">
            first card that is manually inserted with different content
            </div>
        <?php endif; ?>

        <a href="<?php the_permalink(); ?>" class="col_4 card bar no-pad <?php if ($c % 3 == 0) { echo 'last'; } ?>">
        <?php if (has_post_thumbnail()) { ?>
            <div class="feature-image c-1">
                <?php the_post_thumbnail('medium'); ?>
            </div>
        <?php } ?>
            <div class="excerpt-wrap">
                This is a post from within Wordpress
            </div>
        </a>

        <?php if ($c == 7) { ?>
            <div class="col_4 card bar">
                Last card that is manually inserted with different content
            </div>
        <?php } ?>


    <?php 
        $c++;
        endwhile; 
    ?>
    </div>                        
<?php
    endif;
    wp_reset_postdata(); 
?>

7 , , 7 ($ c == $sub- > post_count)

enter image description here

0

: , , , .

. , , ​​:

<div class='row'>
  <div class='static'>
  </div>
  <div class='static'>
  </div>

  #here the loop will create
  <div></div>
  <div></div>
  <div></div>

  <div class='static'>
  </div>
  <div class='static'>
  </div>
</div>

, i.

, , , 1,2,3 $c. , $c = 1, 2 divs, $c = 3, 2 div. Reset $c 1, $c = 3 , , $c!= 3, 2 div.

0

All Articles