A
A
Alex Kizyma2018-12-27 16:58:38
PHP
Alex Kizyma, 2018-12-27 16:58:38

How to improve Bootstrap column loop?

Cycle for Bootstrap columns The essence of the cycle is this: if post 3 or 6 is closed, but how to do what when posts 5 or 4 should also be buried (that is, how to check if this is the last post also be closed)

<?php

      $args_montaj_system = array(
        'teg_pages' => 'montazh-sistemi-opalennya',
         );

      $posts_montaz = new WP_Query($args_montaj_system);

      $m = 1;

      if ($posts_montaz) {
        while($posts_montaz->have_posts()): $posts_montaz->the_post(); 
          $thumb_id = get_post_thumbnail_id();
          $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);

          if (($m == 1) || ($m == 4)) {
            echo "<div class='row'>";
          }
          ?>


            <div class="col-md-6 col-lg-4">
              <a href="<?php the_permalink(); ?>" class="wrap-syst-post">
                <div class="image_syst-post" style="background-image: url('<?=$thumb_url[0];?>">
                  <!-- This image -->
                </div>
                <h4 class="title_syst-post">
                  <?php the_title(); ?> 
                </h4>
              </a>
            </div>

      <?php
          if (($m == 3) || ($m == 6)) {
            echo "</div>";
          }
          $m++;

          if ($m == 6) {
            $m = 1;
          }
        endwhile;
      }

      wp_reset_query();  // Restore global post data

      ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marat Garifullin, 2018-12-27
@Brain_code

Why do you want to open/close? Write once at the beginning and at the end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question