douqian2957 2014-04-03 10:08
浏览 34
已采纳

php中的Bootstrap自动生成行(网格系统)

I want to get 4 thumbnails in row but in next code i will get one thumbnail in one row. How i can get 4 thumbnails in one row and next automatic create new row?

<div class="row">
    <div class="col-md-3 col-lg-3">
        <?php foreach($products as $product) : ?>
        <a href="#" class="thumbnail">
            <span class="label label-warning pull-right">TOP</span>
            <img src="<?php echo $this->basePath('img/placeholder.gif') ?>" alt="..."></img>
                <div class="caption">
                    <h3><?php echo $this->escapeHtml($product->title); ?></h3>
                    <p>
                    <?php echo $this->escapeHtml($product->description); ?>
                    <br>
                    Cena: <span class="label label-success"><?php echo $this->escapeHtml($product->price); ?></span>  
                    </p>
                    <p>
                    Lokalita: <span class="label label-info"><?php echo $this->escapeHtml($product->location); ?></span>
                    </p>
                </div>
        </a>

    <?php endforeach; ?>
</div>

  • 写回答

1条回答 默认 最新

  • dongpo1216 2014-04-03 10:31
    关注

    You can try something like that (not tested), using a $count variable to store the number of thumbnails so far :

    <?php 
    $count = 0;
    foreach($products as $product) : 
    
        // open a new row
        if (!$count%4)
            echo '<div class="row">
                <div class="col-md-3 col-lg-3">'
    ?>
    <a href="#" class="thumbnail">
        XXXX
    </a>
    <?php
        // close row if there is 4 thumbnails in it
        if ($count%4 == 3)
            echo '</div></div>';
    
        $count++;
    endforeach; 
    
    // close the row at the end if the last one wasn't full
    if ($count%4>0)
        echo '</div></div>';
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?