The Twenty Eleven Theme has some decent code comments that explain what’s happening.
Quick and dirty overview:
All comment functionality goes in comments.php
. You include it into your template with the aptly named comments_template
which does a lot of stuff (sets up the current commentor, ect) other than just including `comments.php
Your comments.php
template might look something like this.
<?php
// Is the post password protected? Maybe you want to deal with that.
if(post_password_required())
{
// show a message to the users about the password requirement.
// `return` out of the file, don't show anything else
return;
}
// display the comments if they exist
if(have_comments())
{
// maybe a header or something here
// wp_list_comments (http://codex.wordpress.org/Function_Reference/wp_list_comments)
// actually displays the comments -- it will just work if
// you use it without any arguments
wp_list_comments();
// You can also specify a custom callback to display things:
// wp_list_comments(array('callback' => 'your_comment_callback'));
}
// are comments open? display the comment form!
if(comments_open())
{
// `comment_form` does all the work. You can customize it
// with arguments and filters. Like wp_list_comments this
// will just work.
// http://codex.wordpress.org/Function_Reference/comment_form
comment_form();
}
else
{
// display a message about comments being close for visitors
// this optional -- personally, I prefer to show no message.
}
Take a look at the Twenty Eleven’s comment callback for some real insight in ways that you can display comments themselves.