Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些数据只想在帖子有一条或多条评论时才显示。当有 0 条评论时,我不想显示任何内容。
逻辑是这样的:
如果评论数 > 0 { 这样做 } 否则 { }
如果有人可以帮助我解决这类事情的 PHP 代码片段,我们将不胜感激。
$nr_comments = get_comments_number( $post_id ); if($nr_comments > 0){ //we have comments and do this } else{ //we don't have any comments yet and do something else }
注意:此标签必须在循环内。
由于这是循环,因此您不需要$post_id.
$post_id