I want to add a comments section in index.php
of WordPress.
I added the following code:
<td align="left" valign="top">
<?php $withcomments = 1;comments_template(); ?>
</td>
Comments are shown because of the above code, but when a user adds a comment on the index page, it redirects to a default post and also adds that comment to that default post.
Is it possible to make comments on the index page and also have them shown in the index page? If anyone can help me it will be appreciated.
It depends a lot about how your theme is structured: loop is written in single.php file directly, or there is a loop file which is included in both single.php and index.php .
Your homepage should be either home.php or index.php ( usually the second version ). If the loop is shared for both single post and index, you should find something like this:
and replace it with something like this:
If your single loop is different from your homepage loop, then you should copy the code that post the comment form from the single loop into the index loop.
Comments can be enabled on
pages
and / orposts
.If your wordpress front page displays a
static page
you can enable comments on it.If it happens to display “Your latest posts,” it’s simply a list of some recent posts (formatted according to your theme). There’s no single item, post or page, there to accept comments.
You can find out how this is set up for your WordPress installation by looking at Settings / Reading on your dashboard.