Customize WordPress Comments template

By default you use the following function in order to display the template used for the comments :


<?php comments_template(); ?>

You may disable the addition of comments using the administration panel under each page configuration.

However if you need more freedom on interacting with the template you will need to take control over the function or use a different method.

The above function will display the number of comments added, the author name above each comment, the comment itself and the posted date. Optionaly the form to add a comment.

If you only need to display comments and nothing else then use the following lines :

<?php
$args = array(
	'status' => 'approve',
	'number' => '15', // whatever number of comments you wish to display.
	'post_id' => 18, // use post_id, not post_ID - replace 18 by your post ID
);

$comments = get_comments($args);

// Browse all comments one by one and display the content :
foreach ($comments as $comment) :
	echo($comment->comment_content);
endforeach;

?>

You might also like using the function : wp_list_comments(), but I thought using the get_comments will get us straight to the point on displaying exactly what we need.

For more information :

http://codex.wordpress.org/Function_Reference/get_comments

http://codex.wordpress.org/Function_Reference/wp_list_comments

Want more information?

Related links will be displayed here in this section for you to pick up another good spot to get more details about Web marketing and Search Engine Optimization. There will be some sites which we selected to ease the work of any webmaster or/and web marketer on the Internet.