Need to show comments on your Blog’s home page? This is how you do it

Need to show comments on your Blog’s home page? This is how you do it

One of my favourite reasons why I love WordPress is that they’ve made it really easy to customise things. Themes are relatively easy to code and edit to your liking.

In this tutorial, I am going to show you how to add comments to your articles that are displayed on your homepage. This may be a good thing to do, especially if you publish a Blog post every day at the same time, and only show one post per day.

In this tutorial, I have started with a fresh WordPress install, but you can easily do this to any theme you would like as I have also showed.

The Original Look

I’m using the default WordPress theme – Twenty Ten 1.3, and this is what it looks like at the start.

Make Your Changes

In WordPress, open up your Theme Editor which is under Appearance and select your current theme from the top right-hand side dropdown box. Select your index.php file of your theme (or an alternative file that controls your theme’s homepage layout.

In that file, you should see code that starts your loop which contains the following code:

<?php /* Start the Loop */ ?>

<?php while ( have_posts() ) : the_post(); ?>

Keep scrolling down until you find the line in your template which ends the loop:

<?php endwhile; ?>

The loop can also just end with a } so keep a lookout for that!

Just above the “endwhile” line, you need to place the following code:

<?php $withcomments = “1”; comments_template(); ?>

The $withcomments=”1″; line is the most crucial part as without it, your comments won’t show. Also, remember remove the PHP tags if they are already open on where you  have to place the above code.

The Outcome

Now you have comments displayed on your home page blog posts.

The Full Code

This is what my index.php file now looks like after adding the two PHP statements.

Example 2: Another Theme

Just in case your theme is a little different, I’ll show you the code to change for another template.

The below image is on another theme that I designed.

As you can see on the homepage, it displays 2 comments, but they are not shown.

I then added the two lines to the index.php file, only this time, the End While loop was just a }.

 

After making the change, you can see that comments now appear on articles on the homepage.

If you have any questions, please don’t hesitate to ask in the comments.

 

About the Author