PHP的MOD自动生成行bootstrap& WordPress的

时间:2014-08-01 18:01:16

标签: php wordpress twitter-bootstrap

我的wordpress中有这个代码。在collection.php中

当有3个帖子和3个帖子关闭时,此代码会生成行。

当我有3个,6个或9个帖子工作正常但问题是我有4个或5个帖子,因为它没有关闭且代码保持打开状态。

任何人都可以帮助我。我非常感激。

问候

$i = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post();    
$i++; 
if($i%3 == 1){echo '<div class="row">'; }
     $args = array(
       'post_type' => 'attachment',
       'numberposts' => -1,
       'post_status' => null,
       'post_parent' => $post->ID
      );

      $attachments = get_posts( $args );
         if ( $attachments ) {
            foreach ( $attachments as $attachment ) {
               echo '<div class="col-md-4">';
                echo '<a href="';
                echo the_permalink(); 
                echo '">';
               echo wp_get_attachment_image( $attachment->ID, 'full' );
                echo '</a>';
                echo '<h3 class="category-title"><a href="';
                echo the_permalink();
                echo '">';
                echo the_title();
                echo '</a></h3>';
               echo '</div>';


              }
         }
if($i%3 == 0){echo '</div>';}
     endwhile; endif; 

1 个答案:

答案 0 :(得分:0)

if($i%3 == 0){echo '</div>';}
endwhile; endif; 

更改为:

if($i%3 == 0){echo '</div>';}
endwhile; endif;  
if($i%3 != 0){echo '</div>';}