Load 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 {@see ‘comments_array’} filter hook with the list of comments and the post ID respectively.

The `$file` path is passed through a filter hook called {@see ‘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.

Will not try to get the comments if the post has none.


comments_template( $file = '/comments.php', $separate_comments = false )
 (string) Optional. The file to load. Default '/comments.php'.
Default: '/comments.php'
 (boolean) Optional. Whether to separate the comments by comment type. Default false.
Default: false


(null) Returns null if no comments appear.


function comments_template( $file = '/comments.php', $separate_comments = false ) {
	global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;

	if ( !(is_single() || is_page() || $withcomments) || empty($post) )

	if ( empty($file) )
		$file = '/comments.php';

	$req = get_option('require_name_email');

	 * Comment author information fetched from the comment cookies.
	$commenter = wp_get_current_commenter();

	 * The name of the current comment author escaped for use in attributes.
	 * Escaped by sanitize_comment_cookies().
164 more lines...
WP Trac GitHub

Link here