I have single.php file and Im showing single post in it. I want to show comments on related to this post under this post. But the problem is I
m getting comments all of comments below any post.
Below is my single.php code
<?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; endif; ?>
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my comments.php code
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?'
) ?>
Thanks in advance.
use is_single() to check the post :
Remove the
foreach
from single.php:Then, add it to your comments.php and pass
$comment_args
inget_comments()
like so:have a look the the function reference for
get_comments
to see the list of arguments you can pass intoget_comments
Single.php code. Remove
get_comments()
You need to
get_the_ID()
per single page comment, then add the comment query.