WordPress.org

Ready to get started?Download WordPress

Forums

Comments in Main Thread (5 posts)

  1. blurredv
    Member
    Posted 3 years ago #

    Hi all,

    I'm trying to find if it's possible to change the way comments are viewed on my wp site. I'd rather see a list of comments under the posts in my main thread then have people navigate away to a specific comments page...

    Is this possible and if so, can anyone help out with the coding that would be involved?

    Simplicity is the key to my site and I'd like the comments to elegantly sit under the post itself...

    Cheers,
    JB

  2. David Gard
    Member
    Posted 3 years ago #

    Yes it is possible, and quite easy.

    Comment count -
    <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?>

    Show comments - see the codex here for more information
    <?php get_comment($id, $output); ?>

  3. blurredv
    Member
    Posted 3 years ago #

    Thanks duck_boy!

    So do I just add this code to the 'comments.php' page or do I need to replace code? Not 100%.

    Cheers,
    JB

  4. David Gard
    Member
    Posted 3 years ago #

    If you want your comments displayed on each post you would need to add it to single.php, inside The Loop (look it up if you are not sure what The Loop is). You will need to amend slightly so that the $id and $output variables hold the correct information.

    You will then need to add a little code to display what you want. For example, the following would display the Author and then the Comment and should hopefully get you going -

    $comments_ids = $wpdb->get_results("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID='".the_id());
    
    foreach($comment_ids as $comment_id){
    	<?php $comment = get_comment($comment_id); ?>
    	<h3>Comment by <?php echo $comment->comment_author; ?></h3>
    	<p><?php echo $comment->comment_content; ?></p>

    }`

  5. Root
    Member
    Posted 3 years ago #

    Cant the post id be extracted without another db query ?

Topic Closed

This topic has been closed to new replies.

About this Topic