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.

26 comments

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.

Comments

MacBros says:

That’s actually a great idea. Like showing the latest comment instead of a link to the comments form. Neat idea.

rich says:

Yeah I thought it was useful.

A new theme I’m developing really has it developed a lot, lots of comments bits and pieces so it’s just one them. I’ll post more on them.

TERA RMT says:

[b][URL=http://www.rmtvip.jp/rmt/tera.html]TERA RMT[/URL][/b]
[b][URL=http://www.rmtvip.jp/rmt/ro2.html]??????????2 RMT[/URL][/b]
[b][URL=http://www.rmtvip.jp/rmt/ro2.html]RO2 RMT[/URL][/b]
[b][URL=http://www.rmtvip.jp/rmt/redstone.html]??????? RMT[/URL][/b]
[b][URL=http://www.rmtvip.jp/rmt/redstone.html]REDSTONE RMT[/URL][/b]

thank you for share,good post

Esteban says:

Thank you so much for this code!!

Jack says:

Great article, I have been looking for something like this but yours is the simplest solution. Keep up the good work!

Wire Grid Panel says:

Very happy to see your article, I very much to like and agree with your point of view. Thank you for sharing. At the same time,i love Wire Grid Panel very much .Welcome to look at my website and blog articles.Hope we can become good friends, and exchange and to help each other! Thanks!!

Ryan says:

Anyway to have the leave a reply box (like the one im typing in right now) appear under the comments?

About the wonderful, very pleased to see this article, learn some things, and view the text is recognized. Thank you for sharing. At the same time ,i love Children Sandals and Buy Tote Bags. but i think ,Five Fingers Shoes And Slippers and Sandals I think I would be more helpful, thank you!

Will says:

Very useful post! What about if I want to decrease the output of the comment excerpt to say just 5 words (instead of about 20 which is the default excerpt length)?

rich says:

Will, I’ll look into that for you, I’ll see if I can test it out tomorrow.

Diana says:

Thank you! I´m trying to code a facebook-like theme

Sudipta says:

Hi,
I have tried to input your code into my blog index.php.

But it is not working.

Please check below:

· <a href="#respond”> 

<!–

–>

post->ID));
$count = 1;
?>

– Latest by:

<?php if ($count++
&lt?php comment_author_link(); ?>

No comments so far

kalina says:

Very useful post! Thanks a lot for this code!!

supra says:

It’s so lucky for me to find your blog! So shocking and great!

christian says:

Thank you for sharing your stuff on blog.It is doubtless that we have similar interests.Something are very helpful to me.

Very useful post! Thanks a lot for this code, saved my life! :D

Discount New Era Hats says:

I enjoyed this post Abhishek. It was certainly creative and not what I was expecting when I clicked on the title – a title I might add, which is quite good. I know I had to find out what ways ‘guaranteed’ I could grow my list.

rebekah ford says:

This is a great bit of code and has helped me out with a WordPress project that I’m doing right now. I’m trying to expand on it however and add a limit to the number of comments showing and also calling them by a category ID so that I can make them category specific like I have with the posts on each of my pages.

I’ve tried various WordPress variables but no joy. Do you have any idea how I might do this?

moster energy says:

I enjoyed this post Abhishek. It was certainly creative and not what I was

expecting when I clicked on the title – a title I might add, which is quite

good. I know I had to find out what ways ‘guaranteed’ I could grow my list.

keylogger says:

Great idea! Unfortunately I can’t get this working in wp 3.3. I get a Parse error: syntax error, unexpected T_STRING. Any idea why?

David Kennedy says:

Check all the single and double quotes: some of them seem to be wrong or perhaps they get changed by cut and pasting.

And change &lt to < then it works!

I also changed the No comments so far line to
comment_status) { echo ‘No comments so far’; } ?>
so that it doesn’t show if comments are closed.

David Kennedy says:

….. that new line didn’t show correctly.
What I added to the line was checking if the post comment status is open.

Various people in every country get the personal loans in different banks, just because this is simple.

Readers want to read something they did not know before. That is why it is better that you should conduct relevant research before writing. You will be able to write better content this way.



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