Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I make the wordpress comments work with:

include(TEMPLATEPATH."/comments.php");

instead of:

comments_template( '', true );

Ay ideas? Ty

share|improve this question
2  
why do you want to do that? answer is probably you can't do it anyway; comments_template() is actually checking and preparing a lot of needed stuff before calling the comments.php file. –  Michael Aug 4 '12 at 13:28
add comment

2 Answers

up vote 4 down vote accepted

Short answer: you can't.

Longer answer:

You can include comments.php as a template-part file inside another template, via:

get_template_part( 'comments.php' )

...but that won't actually make comments work, because the comments_template() template tag does far more than merely include the comments.php template-part file. In order to make comments actually work when using get_template_part() as opposed to comments_template(), you'd need to duplicate all of the functions performed by comments_template(). And if you need to duplicate all of that code in order to make comments work, you might as well just use the function itself.

share|improve this answer
add comment

That wont work because we cannot include the comments.php file as a template file. Our comments.php file doesn't contain the necessary codes to do SQL operations on database and fetch the comments to display.

So instead including that file as a template file we should call the function comments_template() to show the comments.

Wordpress uses comments_template() function to get the file and display the comments, if we don't provide file variable wordpress uses default comments.php to process the result.

Note -

If you're curious about how to load a different comment template then here's the code

<?php comments_template( '/comments2.php' ); ?> 

Reference - Comments_template

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.