Loading...


Loading...

Welcome!

Sign up for a free account, or log in here.

Member Login

You can login by following the link.

Not a Member? Sign up! It's Free!

Please feel free to register.

Click to log in.

Display Comments on Index Page Post in WordPress

This is actually a useful bit of code if you want to do a little bit of manipulation on the index page of your wordpress blog. Rather than the ‘x comments, click here to see them’ link, you could choose to display the last one or two comments in excerpt format.

Here is how you do it:

<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>

Update: This piece of code has been fully implemented in a new theme I created, you can see the screenshots and read about it on the theme release page: . You can visit a working copy of this, in the wild so to speak, on my personal blog.



Leave a Reply



You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


The English Guy on Twitter

Raised Paper WordPress Theme

Raised Paper WordPress Theme screenshot
Theme Price

Onyx WordPress Theme

Onyx WordPress Theme screenshot
Theme Price

Victoriana WordPress Theme

Victoriana WordPress Theme screenshot
Theme Price

Expression Blue WordPress Theme

Expression Blue WordPress Theme screenshot
Theme Price

Premium WordPress Theme Release: Natural Green

Premium WordPress Theme Release: Natural Green screenshot
Theme Price

Theme Release: Ikon WordPress Theme

Theme Release: Ikon WordPress Theme screenshot
Theme Price

Shocking WordPress Theme Release

Shocking WordPress Theme Release screenshot
Theme Price

Digitalis WordPress Theme Release

Digitalis WordPress Theme Release screenshot
Theme Price

WordPress Theme: OpenAir Theme

WordPress Theme: OpenAir Theme screenshot
Theme Price

WordPress Theme: Very English

WordPress Theme: Very English screenshot
Theme Price

News Print v3.0 WordPress Theme Released

News Print v3.0 WordPress Theme Released screenshot
Theme Price

Reclamation WordPress Theme

Reclamation WordPress Theme screenshot
Theme Price