Adding post count (5 posts)

  1. myusernameok
    Posted 5 years ago #

    Hi all,

    Im using this code:

    $comments = get_comments('status=approve&number=5');
      foreach($comments as $comment) :?>
      <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;?> 
        Who: <?php echo($comment->comment_author);?><br />
        About: <a href="<?php echo get_permalink($my_id) ?>#comment-<?php echo $comment->comment_post_ID?>" title="on <?php echo $title ?>"><?php echo $title ?></a><br />
        What they said: <?php echo($comment->comment_content);?><br />
        When they said it: <?php echo($comment->comment_date);?><br />
      <?php endforeach;?>

    to output the most recent comments on a homepage but am struggling to find the correct code that also outputs the comment count for each post with a recent comment. All I have managed to do so far is zero for all comments.

    Any ideas?
    Many thanks.

  2. Rev. Voodoo
    Posted 5 years ago #

    are you using comment_number ?

  3. myusernameok
    Posted 5 years ago #

    on the homepage its just the code above but on single pages each comment is assigned a number. Is that what you mean?

  4. myusernameok
    Posted 5 years ago #

    Ah, sorry. Comment_number just returns 0 for everything.

  5. myusernameok
    Posted 5 years ago #

    A little more info in the hope someone knows the answer.
    Im using the code in post 1 to create a page of latest comments so when a new comment is left it goes to the top (Like how a forum works) . Its all working fine but I am unable to work out how to show the amount of comments on each post next to each latest comment.

Topic Closed

This topic has been closed to new replies.

About this Topic