Friday, July 31, 2015

Enabling Comments

To enable comments on just posts, one needs to implement the following (adding to pages is a matter of updating page.php).

First add the following just below the content on single.php.

single.php
<?php
if (comments_open() || get_comments_number()) :
  comments_template();
endif;
?>

Then create a comments.php template file:

comments.php
<?php
if (post_password_required()) {
 return;
}
?>
<div id="comments" class="comments-area">
  <?php if (have_comments()) : ?>
    <ul class="comment-list">
    <?php wp_list_comments(); ?>
    </ul>
  <?php endif; ?>
  <?php comment_form(); ?>
</div>

Interestingly, one does not need to implement the comments-popup.php listed in the template hierarchy unless one enables comment popups.  At this point, we have considered all the primary files (and some secondary ones) in the WordPress template hierarchy <https://developer.wordpress.org/themes/basics/template-hierarchy/>

No comments:

Post a Comment