2017-10-28 137 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> 

所以其實我會艾克實現是有裏面的第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> 
相關問題