1 回答
TA贡献1815条经验 获得超13个赞
我假设您正在尝试显示col-sm-6大于 4 的帖子的类。
有几件事,你可以做它来使它工作。
删除循环$counter后递增的代码。foreach我们将在下面的第 2 步中执行此操作。
foreach( $posts as $post):
//$counter++; This should be commented.
相反,我们应该if在您检查状态的块内增加这个计数器。
if ('publish' === $post->post_status):
//echo $counter; //Comment this out
$counter++; //increment it here
?>
最后一步是确保当$counter大于或等于 4 时显示我们的类。正如@Kaperto 所建议的,您不需要在draft此处检查状态,因为您已经在检查上述状态。
所以取出以下行
<div class="col-custom <?php if ('draft' != $post->post_status && $counter == 4): echo 'col-sm-6'; endif; ?>">
并将其更改为
<div class="col-custom <?php if ($counter >= 4): echo 'col-sm-6'; endif; ?>">
- 1 回答
- 0 关注
- 122 浏览
添加回答
举报
