How can I build a loop with the bootstrap grid in several sizes?

Asked

Viewed 105 times

0

I am currently working with wordpress and came to the following doubt...

My current loop is like this... (8 Items)

      COL-MD-6                     COL-MD-6        
    --------------------------   --------------------------

      COL-MD-6                     COL-MD-6        
    --------------------------   --------------------------

      COL-MD-6                     COL-MD-6        
    --------------------------   --------------------------

But I need something like this...

      COL-MD-4              COL-MD-4             COL-MD-4        
    -----------------   -----------------  ----------------

      COL-MD-6                       COL-MD-6                  
    --------------------------   --------------------------

      COL-MD-4              COL-MD-4             COL-MD-4        
    -----------------   -----------------  ----------------

If anyone has the solution, thank you very much!

1 answer

1

I believe that’s the logic:

<?php

$count = 0;  if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++;?>

    <?php if( $count <= 2 ) { ?>

        <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">

    <?php } elseif ( $count >= 3  and $count  <= 5) {   ?>

        <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">

        <?php if( $count == 5 ){ ?>

            <?php $count = 0; ?>

        <?php } ?>

    <?php } ?>

            <!-- seu código aqui -->

        </div>

<?php endwhile; endif; ?>
  • Good afternoon, I understood more or less what you wanted to do, but it didn’t turn out the way I wanted, it got a little bit more... but I appreciate the push, I’ll try to adjust this code! Obrigadooo mann!

  • 1

    I took a test here and it worked out the way you mentioned it, give me more details of how it was to look that I help you.

  • Oops! Beauty? It worked out after, I who wavered here Ahaaha! It worked successfully my darling! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.