Title: &lt;?php if (has_comments()) ?&gt; ?
Last modified: August 19, 2016

---

# <?php if (has_comments()) ?> ?

 *  [cpkid2](https://wordpress.org/support/users/cpkid2/)
 * (@cpkid2)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/ltphp-if-has_comments-gt/)
 * I want one div (#comments-area) to show up if a post has comments and another
   div(#no-comments-area) to show up when a post has no comments. How would I do
   this? Below is my failed attempt. I would really appreciate any help. Thanks.
 *     ```
       <?php if(has_comments()) {
       echo
       <div id="comments-area">
       <?php comments_template(); ?>
       </div>
       } else {
       echo
       <div id="no-comments-area">
       <?php comments_template(); ?>
       </div>
       }
       ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/ltphp-if-has_comments-gt/#post-1452795)
 * Based on your code, it looks like there are a few syntax errors, as well as an
   improper mix of HTML and PHP. Try something like this:
 *     ```
       <?php if (has_comments()) { ?>
       <div id="comments-area">
       <?php comments_template(); ?>
       </div>
       <?php } else { ?>
       <div id="no-comments-area">
       <?php comments_template(); ?>
       </div>
       <?php } ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘<?php if (has_comments()) ?> ?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/ltphp-if-has_comments-gt/#post-1452795)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
