1

I would like to make a "Comment" section on every of my page on my wordpress website.

So if you head to http://www.lolcounter.com/champions/lee-sin, You can see on top of the page the "General Counter Tips" with bellow it, 4 comments.

There is more comment then this and you can see it if you click the "View More Counter Tips" and you can post a tip if you click "Submit a Counter Tip".

My question is, how do I make something similar to this with wordpress ? I actually have multiple page that I want to add this feature on them, but all of them need to have different comments.

Do I make this with a custom post type ? Or I add everything into a table into my DB? or is there any other way?

Thanks for any help :) !

closed as too broad by Howdy_McGee, Pieter Goosen, TheDeadMedic, Mayeenul Islam, kaiser Nov 30 '15 at 10:55

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

3

You can pass the number argument to get_comments() to retrieve only a specific number of comments. They will, by standard, be sorted descending, so you get the latest comments first.

As WordPress automatically seperates comments for each post, you will not have to worry about mixing comments up. This seems to be the easiest way for me.

Multiple comment forms per page -> Passing Post ID

If you need multiple comment forms on one page, you can use several get_comments(), but you have to pass the post IDs for the comments you want to show.

Example:

$postID = 4;
$number_of_posts = 6;

$args = array(
    'number' => $number_of_posts,
    'post_id' => $postID
);

$your_comments = get_comments($args);

Make it dynamic -> Extract IDs from post_meta and loop over them

Post IDs are saved comma-seperated in a field called commentIDs, code would be placed in a single.php for example.

// get IDs for current post
$cmmntIDs = get_post_meta($post->ID, 'commentIDs', true);
$theIDs = explode(',', $cmmntIDs);

// get comments for each ID you defined
foreach($theIDs as $theID) {
    $args = array(
        'number' => $number_of_posts,
        'post_id' => $theID
    );
    $comments = get_comments($args);

    // basic output from the Codex Page on get_comments()
    foreach($comments as $comment) {
        echo($comment->comment_author);
    }
}  
  • I see, but if I want multiple comment form on the same page, there will be conflict right ? – Antoine Dionne Nov 27 '15 at 15:50
  • Not really. You just have to pass the post ID to get_comments() then. It´s your choice where you get those from (fixed or dynamic). – flomei Nov 27 '15 at 15:52
  • I see. I want to make this into a page-teamplate to use on page (not posts). So I would have multiple get_comments() with different IDs. If I use this page-template on another page, this will give me the same comments, or I have to send different ids to the different pages? – Antoine Dionne Nov 27 '15 at 15:56
  • You would have to send different IDs, yes. But you could use post_meta (works for pages too, I think) to pass the IDs in an easy way. Or you find a way to automate which IDs are to be chosen. – flomei Nov 27 '15 at 16:17
  • Alright, well is there a way to send IDs like you say, but have multiple type of comment form ? So I would have my comment form 1, with id 1, and type A, and a comment form 2, with id 2 and type B – Antoine Dionne Nov 27 '15 at 16:27

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