用PHP填充3个项目后循环DIV块

时间:2014-02-18 04:58:55

标签: php jquery html css

我有以下原始HTML代码:

<section class="cols services-modern">
    <div class="container">
        <div class="row-fluid">
            <div class="span4">
                <i class="content"></i>
                <h3>Title</h3>
                <p>Blah.....</p>
            </div>
            <div class="span4">
                <i class="content"></i>
                <h3>Title</h3>
                <p>Blah.....</p>
            </div>
            <div class="span4">
                <i class="content"></i>
                <h3>Title</h3>
                <p>Blah.....</p>
            </div>
        </div>
    </div>
</section>

我想在div填充3个内容之后循环。 到目前为止,我已经做了以下没有运气..

<?php for($i = 0; $i < sizeof($content); $i++) : ?>
<section class="cols services-modern">
    <div class="container">
        <div class="row-fluid">
<?php if($i % 3 == 0): ?>
    <div class="span4">
        <i class="content"></i>
        <h3>Title</h3>
        <?= htmlspecialchars_decode($blah); ?>
    </div>
<?php else: ?>
    <div class="span4">
        <i class="content"></i>
        <h3>Title</h3>
        <?= htmlspecialchars_decode($blah); ?>
    </div>
<?php endif; ?>
</div>
</div>
</section>
<?php endfor; ?>

任何人都可以帮助我发现我的错误,谢谢。

2 个答案:

答案 0 :(得分:0)

这是你期待的吗?

<section class="cols services-modern">
  <div class="container">
    <div class="row-fluid">
    <?php for($i = 0; $i < sizeof($content); $i++) : if($i % 3 == 0): ?>
      <div class="span4"> <i class="content"></i>
        <h3>Title</h3>
        <?= htmlspecialchars_decode($blah); ?>
      </div>
      <?php else: ?>
      <div class="span4"> <i class="content"></i>
        <h3>Title</h3>
        <?= htmlspecialchars_decode($blah); ?>
      </div>
      <?php endif; endfor; ?>
    </div>
  </div>
</section>

答案 1 :(得分:0)

尝试这个..

<?php for($i = 0; $i < sizeof($content); $i++) : if($i % 3 == 0): ?>
<section class="cols services-modern">
  <div class="container">
    <div class="row-fluid">

      <div class="span4"> <i class="content"></i>
        <h3>Title</h3>
        <?= htmlspecialchars_decode($blah); ?>
      </div>
      <?php else: ?>
      <div class="span4"> <i class="content"></i>
        <h3>Title</h3>
        <?= htmlspecialchars_decode($blah); ?>
      </div>

    </div>
  </div>
</section>
<?php endif; endfor; ?>