这个Twenty Eleven Theme 有一些不错的代码注释来解释发生了什么。
快速和肮脏概述:
所有注释功能都可以使用comments.php
. 您可以使用适当的名称将其包含到模板中comments_template
它做了很多事情(设置当前评论员等),而不仅仅是包含“评论”。php
你的comments.php
模板可能如下所示。
<?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.
}
看一下二十一点的
comment callback 了解如何显示注释本身。