I’m using the “Story” theme on my blog, and I love it except for one thing: there isn’t a link to my comments on my posts! I’ve had a look but I can’t figure it out myself, how can I add a comment link back on to all of my posts?
Great question, Leah! The actual process of adding this is very simple. The tricky part comes in telling you where to put the code. This is because every theme is designed so differently.
First, a warning:
Where to put the code
Assuming you want to add this to your blog archive page (the homepage), you want to fist look in your theme’s index.php template. But then this is where it gets tricky. Some themes might include a separate file inside this one (like loop.php). So really, I can’t tell you exactly where to look because every theme is totally different! But I can give you a rough idea. You want to look around for this:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
This bit of code designates the start of The Loop. The Loop is the bit of repeating code for displaying all your posts. Once you’re inside The Loop, you’re good! If you want to look more specifically, you can look for where they output the title, which is done with:
<?php the_title(); ?>
How to display the comment number and link
Once you’ve found where to display the code, here’s the bit to actually do it:
<a href="<?php comments_link(); ?>"><?php comments_number( 'Leave a Comment', '1 Comment', '% Comments' ); ?></a>
This code does two things:
- 1. It adds a link to your comment form for that post.
- 2. It displays the number of comments.
If you want to edit the text you can. The
comments_number() function has three parameters:
- 1. The text that gets displayed when there are no comments. I have it set to
Leave a Comment.
- 2. The text that gets displayed when there is one comment (so ‘Comment’ isn’t plural). I have it set to
- 3. The text that gets displayed for any number of comments greater than 1 (so ‘Comments’ is plural). I have it set to
% Comments. The
%symbol is a placeholder for the actual number.
Hope this helps!
I’m sorry I can’t be more specific with where you place this code, Leah. But hopefully you’ll be able to find a good spot. 🙂