Post Pic

WordPress tip: Include comments in post lists

Many “new generation” themes, as such as P2 include a nice feature named “inline comments”: The option of having comments displayed in your index.php file. Let’s see how to do it.

I have a hard time at first, but including inline comments on your index.php file is just really simple.
Simply paste the following code on your index.php file, where you want the comments to be displayed:

<?php
  global $withcomments;
  $withcomments = true;
  comments_template("/inline-comments.php");
?>

What I did? That's simple: On line 2, I declare that I'll use the global variable $withcomments. I then set its value to true on line 3. Finally, I use the comments_template() function to call my comments file. The /inline-comments.php parameter tells the function to use a specific file for displaying comments, instead of the regular comments.php.

Related Posts

Related Posts

No related posts.

9 Responses

Aug 17 2009 12:42

Hmm, i guess this would be a good tip for themes with few posts, otherwise I don’t think inline comments would be a great idea on a magazine for example :)

But will try this out for sure, thanks for the tip ;)

Aug 17 2009 15:48

I’ve been searching for a way to do this for a while…I can’t wait to test it out…thanks for the tip.

Aug 19 2009 20:36

Very useful tip for blogs. I wil try it! Thank`s

Aug 19 2009 22:50

Any ways of limiting the amount of comments shown? Like the last 3?

Aug 31 2009 17:48

thanks jean. It’s a simple tricks

@Dumitru Brînzan: I agree with you, that’s bad idea on a magazine.

Sep 05 2009 16:11

Excellent work !! I appreciated your work and The author of this post should be appreciated..Keep it up.

Sep 13 2009 20:21

Thanks Jean.

Dec 18 2009 16:44

Good work. There are some very useful Wordpress tips here which I have found very useful. Thank you for sharing them with us.
Ian

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required