首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Wordpress和Bootstrap 3自动生成类别中的行

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

Stack Overflow用户
提问于 2014-07-17 00:43:25
回答 1查看 232关注 0票数 1

我正在使用引导3,我想分组每一行3张贴类别,以获得一个适当的网格系统,但我不知道如何做一个计数器。有人能帮我吗?

这是我的代码:

代码语言:javascript
运行
复制
<?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; ?>

我想要这样的东西

代码语言:javascript
运行
复制
<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>

非常感谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-17 00:49:01

使用PHP的MOD测试剩余部分:

代码语言:javascript
运行
复制
$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; 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24793158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档