2017-10-28 1 views
0

Also der Fall, wenn folgende - ich habe eine WPquery wie auf dem Code unten.WPquery + fügen Zeile jedes nth Element

<section class="row service_block_row bgf" id="page-<?php the_ID(); ?>"> 
     <div class="container"> 
      <div class="row"> 
       <div class="col-sm-12"> 
        <?php 
         $args = array(
         'post_type'  => 'page', 
         'posts_per_page' => -1, 
         'post_parent' => $post->ID, 
         'order'   => 'ASC', 
         'orderby'  => 'menu_order' 
        ); 


        $parent = new WP_Query($args); 

        if ($parent->have_posts()) : ?> 

         <?php while ($parent->have_posts()) : $parent->the_post(); ?> 

         <div class="row"> 
          <div class="col-sm-12 col-lg-3"> 
           <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1> 
          </div> 
         </div> 
         <?php endwhile; ?> 

         <?php endif; wp_reset_query(); ?> 
       </div> 
      </div> 
     </div> 
    </section> 

Was würde ich erreichen möchte, ist die Schleife so arbeiten zu lassen:

<ROW> 
<COL-LG-3> 
<COL-LG-3> 
<COL-LG-3> 
<COL-LG-3> 
</ROW> 

SO in der Tat, was ich erreichen würde lke 4 Elemente in Reihe haben, ohne unterschiedliche Schleifen zu schaffen. Ich weiß, ich soll einige Zähler verwenden, aber ich habe keine Ahnung, wie;/

dank

Antwort

1

Neue Reihe nach 4 cols

<section class="row service_block_row bgf" id="page-<?php the_ID(); ?>"> 
     <div class="container"> 
      <div class="row"> 
       <div class="col-sm-12"> 
        <?php 
         $args = array(
         'post_type'  => 'page', 
         'posts_per_page' => -1, 
         'post_parent' => $post->ID, 
         'order'   => 'ASC', 
         'orderby'  => 'menu_order' 
        ); 


        $parent = new WP_Query($args); 

        if ($parent->have_posts()) : 
        $count=0; 
        ?> 
         <div class="row"> 
         <?php while ($parent->have_posts()) : $parent->the_post(); 
          $count++; 
         ?> 
          <div class="col-sm-12 col-lg-3"> 
           <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1> 
          </div> 

         <?php 
         if($count%4==0) 
         { 
          echo '</div><div class="row">'; 
         } 
         endwhile; ?> 
         </div> 
         <?php endif; ?> 

         <?php wp_reset_query(); ?> 
       </div> 
      </div> 
     </div> 
Verwandte Themen