您需要通过以下方式包括评论功能comments_template()
, 因为这个函数不仅仅包括comments.php
, 文件,但也处理显示注释所需的所有查询和函数。
虽然the Codex doesn\'t really get into details, 你可以看到,by looking at source, 发生了什么:
<?php
/**
* Loads the comment template specified in $file.
*
* Will not display the comments template if not on single post or page, or if
* the post does not have comments.
*
* Uses the WordPress database object to query for the comments. The comments
* are passed through the \'comments_array\' filter hook with the list of comments
* and the post ID respectively.
*
* The $file path is passed through a filter hook called, \'comments_template\'
* which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
* first and if it fails it will require the default comment template from the
* default theme. If either does not exist, then the WordPress process will be
* halted. It is advised for that reason, that the default theme is not deleted.
*
* @since 1.5.0
* @global array $comment List of comment objects for the current post
* @uses $wpdb
* @uses $post
* @uses $withcomments Will not try to get the comments if the post has none.
*
* @param string $file Optional, default \'/comments.php\'. The file to load
* @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false.
* @return null Returns null if no comments appear
*/
?>