2016-02-19 21 views

回答

0

您將需要添加一個計數到將帖子拉入行的循環中。

例如:

<?php $args = array(
    'post_type'  => 'posts', 
    'posts_per_page' => -1 
); 

$posts = get_posts($args); 

if ($posts) : 
$temp_post = $post; ?> 

<div class="row"> 
    <?php $count = 1; foreach ($posts as $post) : setup_postdata($post); ?> 
     <h1><?php the_title(); ?></h1> 

     <?php //This count adds the custom html mark usful if its only a sinle line of markup. 
     echo ($count % 5 == 0) ? '<h2 class="custom-html-markup">Custom Markup</h2>' : ''; ?> 

     <?php // If the markup is longer than a single line. 
     if ($count % 5 == 0) : ?> 
      <div class="custom-html-markup"> 
       <?php the_excerpt(); ?> 
      </div> 
     <?php endif; ?> 

     <?php // This count closes and re-opens the rows 
     echo ($count % 3 == 0) ? '</div><div class="row">' : ''; ?> 
    <?php $count++; endforeach; ?> 
</div> 

<?php $post = $temp_post; 
endif; ?> 
相關問題