How to loop posts in WordPress?

2

I personally need to create this layout for articles in my WordPress loop and I do not know as I could do. I know I'll need some instructions on PHP and some Bootstrap implementations, I'm using this CSS framework.

Does anyone have any idea how I can start thinking about this structure?

    
asked by anonymous 20.07.2015 / 23:14

2 answers

2

There are some posts that have a photo that is 2x1, and others that have a photo of 1x2 (I mean those photos):

In addition, there are 3 columns. Bootstrap can do this easily:

<div class="row">
  <div class="col-md-4">
    <!-- conteudo -->
  </div>
  <div class="col-md-4">
    <!-- conteudo -->
  </div>
  <div class="col-md-4">
    <!-- conteudo -->
  </div>
</div>

Its logic, however, will have to analyze the image of each post inside the loop and verify:

  • If this post is part of this <div class="row"> , or need to start another
  • If the post is listed as one, or two columns.
  • If the post consists of two rows, you will have to skip the third column in the next row
  • Example

    Note: This is not code that you can simply copy and paste into your application - it's just an attempt to show something appeared / p>

    <?php 
     $colunas = 3;
     $coluna_corrente = 0;
     $duas_rows = false;
    ?>
    <?php if ( have_posts() ) : ?>
     <?php while( have_posts() ) : the_post(); ?>
       <?php
        ++$coluna_corrente;
        if ( $coluna_corrente % $colunas == 0 ) {
          echo "<div class='row'>";
        }
        if ( tamanho_relativa_da_foto( $colunas, $post->foto ) < 2 ) { //esse função não existe
         echo '<div class="col-md-4">';
         the_title();
         //algo mais
         echo "</div>";
        } else if ( tamanho_relativa_da_foto( $colunas, $post->foto ) == 2 && !$duas_rows ) {
         echo '<div class="col-md-8">';
         //etc...
         echo '</div>';
        } else {
          $duas_rows = true;
          echo '<div class="col-md-4">';
          //...
          echo '</div>';
        }
        if ( $coluna_corrente == $colunas ) {
          echo "</div>";
        }
       ?>
     <?php endwhile; ?>
    <?php endif; ?>
    
        
    21.07.2015 / 01:26
    1

    I suggest you use the bootstrap grid link to create the layouts. assembling the grids first and then implementing the loops. link

    Well, I think it's something you have to use:

    <div class="row">
      <div class="col-sm-6">  
    
    
        <?php if (have_posts()) : ?>
          <?php $number = 0 ?>
          <?php while (have_posts()) : the_post(); ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
             
    
                <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><p><?php echo the_content(); ?></p></a>
              
     
            </article><!--col--> 
            <?php $number++; ?>      
          <?php endwhile; ?>
        <?php endif; ?>
      </div>  
    
    </div>  

    You define how the grid will be represented and then create the loop to bring wordpress information

        
    21.07.2015 / 00:28