1

I have three pages, and I want them all to display the comments form from a post with id=343. What code would I use within the pages to make that happen?

Here is what I've tried:

<?php
$id=343; // sample, I get the latest post id of a particular category
comments_template();
?>

But that doesn't work, it just shows the blank comment form from the page. Any thoughts / suggestions?

2 Answers 2

2

Use get_comments() and pass the post ID as parameter:

$comments = get_comments(
    array (
        'post_id' => 343
    ) 
);

foreach ( $comments as $comment )
{
    // Just to give you an idea of the available data.
    // You will probably do something better with it. :)
    var_export( $comment );
}

Related: Bug #20572 ($post_id not passed to comment_open() from comment_form()) was fixed just two days ago.

-2

use this if you want to show comment on a specific post is_single('1')

2
  • This is not what I'm trying to do. Lets say I have three pages, and I want them all to display the comments form from post (id=343). What code would I use within the pages to make that happen? May 1, 2012 at 7:19
  • you can do this by giving or operator like this if(is_single(121) || is_single(5)) May 1, 2012 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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