Wordpress和Bootstrap 3自动生成类别中的行

I'm using bootstrap 3 and I would like to group 3 post categories per row to get a proper grid system but I don't know how to make a counter. Can anybody help me with this?

Here is my code:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();    

     $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>';


              }
         }

     endwhile; endif; ?>

I would like to have something like this

<div class="row">
    <div class="col-md-4">Content</div>
    <div class="col-md-4">Content</div>
    <div class="col-md-4">Content</div>
</div>
<div class="row">
    <div class="col-md-4">Content</div>
    <div class="col-md-4">Content</div>
    <div class="col-md-4">Content</div>
</div>

Thank you very much for your help.

查看全部
dpqaaczn141761
dpqaaczn141761
2014/07/17 00:43
  • wordpress
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复