2017-10-28 5 views
0

次の場合は、次のようになります - 下のコードのようなwpqueryがあります。WPquery + n番目の要素ごとに行を追加します

<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> 

私は何を達成したいことは、ループがそのように作業することです:

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

SO実際に私は達成するためにLKEなるのかは、異なるループを作成せず、行内部の4つの要素を持つことです。私は、私はいくつかのカウンタを使用する必要があります知っているが、私はどのように何の手がかりもない;/

おかげ

答えて

1

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> 
後に新しい行を追加します
関連する問題