Forums

How to display last comments (without using the widget)? (2 posts)

  1. tomasi514
    Member
    Posted 2 years ago #

    Here is the code I found on a blog:

    <div class="post-recent-comment">
    <?php
     $comment_array = array_reverse(get_approved_comments($wp_query->post->ID));
     $count = 1;
    ?>
    <?php if ($comment_array) { ?>
    
    <span class="comment"><?php comments_number('No comment','1 comment','% comments'); ?></span> – Latest by:
      <ul class="commentlist">
     <?php foreach($comment_array as $comment){ ?>
      <?php if ($count++ <= 2) { ?>
       <li>&lt?php comment_author_link(); ?><br /><?php comment_excerpt(); ?></li>
      <?php } ?>
     <?php } ?>
      </ul>
    <?php } else { ?>
     <span class="comment">No comments so far</span>
    <?php } ?>
    </div>

    I put it on my homepage but it does not seam to function well as it always display "No comments so far" while I have already made and approved a couple of them.

    Can someone help me here ?

  2. tomasi514
    Member
    Posted 2 years ago #

    All right, I understand the parameter we have to use, details here:
    http://codex.wordpress.org/Function_Reference/get_approved_comments

    Here I do not want to display only a specific post's comments, I want to display last comments within all posts of a category or of all the website.

    Is there a way to do this?
    Would be great.

Topic Closed

This topic has been closed to new replies.

About this Topic