Hey,
You need to add <?php comments_template(); ?>
(note the s) into a file – you are correct :). However you can either add it to your index.php (main template) or create a single.php (the post template) which is used when a single post is displayed.
To add to your index.php, follow the below. However…I’m not sure if it still works. I think it does, but if it doesn’t…have a go at what I detail underneath this!
Inside your index.php (the “main template”) and after your post content (i.e. where you print out the post text, the number of comments, date and time, stuff like that), add in the comments_template()
tag. When you are viewing a single post, WordPress will include the comments list and form; when you are viewing multiple posts (like you do on the front page of your site) it isn’t included.
If this doesn’t work then you will have to create your own single.php template. See below for my guide on how to do this.
To create your own single.php (the post template):
Create a *new* file, called “single.php” inside your theme directory. This is the template used when you are viewing a single post (and therefore the one you want comments on). You can pretty much copy your “index.php” into this file, as that’s the layout you want the page to have.
After you have done this, on the part of the page where you want the comments to be displayed, you need to add <?php comments_template(); ?>
– this will display the comments form and list as defined in “comments.php”. Normally you’d have this after the post and so after the post-specific stuff (like where you have the template tag the_content()
) you would add the comments_template
tag.
There are a few differences between the single.php and index.php templates – mainly that the index.php displays a list of posts whereas single.php lists just a single one. Have a look at the default template’s “single.php” for how you modify the main loop, but for mine the only difference is thus:
The main template (index.php) has a loop of <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
post content here
<?php endforeach; else: ?>
<?php _e('Sorry, no posts matched your criteria.'); ?>
<?php endif; ?>
The single page template (single.php) has a loop of <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
post content here
<?php comments_template(); ?>
<?php endwhile; endif; ?>
“Post content here” is probably the same for both – i’ve add in where I have my comments_template() call too.
**********
Rob