我如何生成,这两个div与类(text-left,text-right)序列
<div class="blog-post text-left">
<figure class="post-image">
<img src="images/image.png" alt="Image">
</figure>
</div>
<div class="blog-post text-right">
<figure class="post-image">
<img src="images/image.png" alt="Image">
</figure>
</div>
<div class="blog-post text-left">
<figure class="post-image">
<img src="images/image.png" alt="Image">
</figure>
</div>
<div class="blog-post text-right">
<figure class="post-image">
<img src="images/image.png" alt="Image">
</figure>
</div>
等...
答案 0 :(得分:0)
我写了这个解决方案:
<?php
$count = 0;
$classes = array('text-left', 'text-right');
for ($i = 0; $i < 10; $i++) {
$count = ++$count % count($classes);
$class = $classes[$count];
?>
<div class="blog-post <?php echo $class?>">
<figure class="post-image">
<img src="images/image.png" alt="Image">
</figure>
</div>
<?php } ?>