Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • GOT IT! Try this. Be sure to put it on the main index template. Good luck:

    Normally, we will put a recent comment widget on the sidebar of our blog. That widget will show all recent comments taken from all posts. But now, we want to do something different. We want to show the recent comment(s) for each of our post on the main page. Something like the Gizmodo (but of course they are not using WordPress). The recent comment(s) can be shown under each post, or next to it, depends on your theme and CSS styling. It will definitely look good on a grid theme.

    Code Implementation
    Here is the way to implement it. Open your index.php file, and paste the following code inside the Loop, anywhere before the <?php endwhile; ?>. Preferably after <?php the_content(); ?>.

    <!-- recent comment of each post -->  
    
    <div class="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><?php comment_author_link(); ?>  <?php comment_excerpt(); ?> </li>
                <?php } ?>
            <?php } ?>  
    
    <?php } else { ?> <!-- if there was no comment in that post,yet -->
            <span class="comment">No comment so far</span>
    <?php } ?>
    </div>  
    
    <!-- end recent comment-->
    <!-- recent comment of each post -->
    
    <div class="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><?php comment_author_link(); ?>  <?php comment_excerpt(); ?> </li>
    			<?php } ?>
    		<?php } ?>
    
    <?php } else { ?> <!-- if there was no comment in that post,yet -->
    		<span class="comment">No comment so far</span>
    <?php } ?>
    </div>
    
    <!-- end recent comment-->

    Some explanation: this will fetch comment for each post, with the help of Post ID and will display latest 2 comments. You can change that count to any number you want. You just have to modify the line that says <?php if ($count++ <= 2) { ?>. Simple, right?

    No. This seems to be a popular question, yet there is no answer. Frustrating.

    Same problem here. Did you figure it out?

Viewing 3 replies - 1 through 3 (of 3 total)