我正在创建一个CMS系统。如果post没有发布那么它将不会在html中呈现,否则在html中显示。因此,如果我从数据库“cms”获取一个关联数组,那么它有一些已发布和未发布的帖子。那么我怎么能跳过未发表的帖子,只显示html中发布的帖子。
我试过条件
<!-- First Blog Post -->
<h2 style = "color:green;">
<?php echo $post_title ;?></a>
</h2>
<p class="lead">
by <?php echo $post_author ;?></a>
</p>
<p><span class="glyphicon glyphicon-time"></span><?php $post_date ?></p>
<hr>
<img class="img-responsive" src="images/<?php echo $post_image ;?>" alt="">
<hr>
<p><?php echo $post_content ?></p>
<a class="btn btn-primary" href="#">Read More <span class="glyphicon glyphicon-chevron-right"></span></a>
<hr>
**<?php } ?> **
**<?php } **// <!--loop ends here so that we can fetch 'n' no. of posts and displaying each post like below HTML -->
?>
</div>
如果发布==发布,那么只在html中显示它,否则不显示它。
检查是否在循环开始时发布了帖子。然后使用continue跳过循环的其余部分。
while(items) {
if(!$post->published) continue;
// this part only runs if post is published
}