<div class="row">
<article>Article One</article>
<article>Article Two</article>
<article>Article Three</article>
</div>
<div class="row">
<article>Article Four</article>
<article>Article Five</article>
<article>Article Six</article>
</div>
下面是我的PHP.这就是我目前所拥有的,但是在开头添加了一行,我不想要.
$i = 0;
echo '<div class="row">';
if ($my_query->have_posts()) :
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?PHP if($i % 3 == 0) {echo '</div><div class="row">';}?>
以上打印如下:
<div class="row"></div> //I don't want this to be in the HTML
<div class="row">
<article>Article One</article>
<article>Article Two</article>
<article>Article Three</article>
</div>
<div class="row">
<article>Article Four</article>
<article>Article Five</article>
<article>Article Six</article>
</div>
我尝试将$i = 0更改为$i = 1,但这也无效.这将在标记中打印出来:
<div class="row">
<article>Article One</article>
<article>Article Two</article>
</div>
<div class="row">
<article>Article Three</article>
<article>Article Four</article>
<article>Article Five</article>
</div>
<div class="row">
<article>Article Six</article>
</div>
我尝试了不同的数字组合,但我似乎无法简单地包装每3篇文章.
解决方法:
写下您的条件如下: –
if(!empty($i) && $i % 3 == 0)