0

I need some help,very much new to wordpress.

I need only comment title and comment date from wp_list_comments function in my post, calling from outside loop, after declared $postid as global variable.

Now I am getting all the information about the comment such as author, date,title,comment etc. So how can I get a particular detail as above?

1

Use get_comments function.Pass Post_id as parameter.See below example

<?php 
$comments = get_comments('post_id=15');
foreach($comments as $comment) :
    echo($comment->comment_author);
endforeach;
?>

for more detail please check below link

http://codex.wordpress.org/Function_Reference/get_comments

  • Deepa, thanks for the answer. But this is not working for me, I dont want to put default ('post_id=15'), $postid should taken from the loop where I declared it as a global variable and I need that particular comment (title,date )outside the loop. Hope you can help me. – Dhans Oct 11 '13 at 11:28
  • @Dhans Please write your code in the question.so I can help you. – dipali Oct 11 '13 at 11:56
  • Here it is....May be little horrible..... <?php global $postid; $postid = get_the_ID();?><!---inside the loop,declared as global variable---> – Dhans Oct 11 '13 at 11:59
  • <ol class="commentlist1"> <?php //Gather comments for a specific page/post $comments = get_comments(array( 'post_id' => $postid, 'status' => 'approve' //Change this to the type of comments to be displayed )); //Display the list of comments wp_list_comments(array( 'per_page' => 8, //Allow comment pagination 'reverse_top_level' => false, //Show the latest comments at the top of the list 'avatar_size' => 0 ), $comments); ?> </ol><!--outside the loop--> – Dhans Oct 11 '13 at 12:03
  • @Dhans your code is working fine at my end.Get the post_id by below code global $post; $postid=$post->ID; and pass 'ID' to 'get_comments' function.Hope it will work. – dipali Oct 11 '13 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.