In this post on Comments, We would like to include some details of code which powers comments section. First two were “Benefits & Drawbacks of Comments” & “Comments & WordPress – Part1”.

This tutorial will help budding WordPress developers understand WordPress comments from a developer’s perspective.

Default Comments Template

WordPress has defined a file named “comments.php” which is used to power comments in the theme. Every Templatic(or WordPress) theme has this file in to the root folder of it.

Study this file and if you want to make changes in to the default comments form, you can do it by using this file or making changes in to this file.

1) Custom Comments Template

Comments template can be customized too. This is useful when you want to have a personalized comments template as per the theme design.

Create a file with prefix-comments.php”:

For example: listing-comments.php. WordPress will recognize that “listing-comments.php” is a comment template as it is having the comments.php word as postfix.

2) Load Comments template

Comments template can be loaded by using ‘comments_template()’ function. comments_template() is located in wp-includes/comment-template.php.

Example:

1.  Default Template:

<?php comments_template(); ?>

2.  Custom Template:

<?php comments_template( '/short-comments.php' ); ?>

3) Displaying comments

wp_list_comments() function is used to display comments specific to post or page.

Syntax:  

<?php wp_list_comments( $args, $comments ); ?>

Tip: A widget can also be developed to show latest reviews on the site.

And that’s it!

Hope this helps you understand comments in WordPress from a programmer’s perspective:)