
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.
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(); ?> <br /> <?php comment_excerpt(); ?> </li>
<?php } ?>
<?php } ?>
</ul>
<?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?
I am not providing any CSS examples for this one because you can do whatever you want with it. Put a light background color or image, style the heading, the <li> tag and so on. Make sure you use class rather than ID though.
There is no Live preview for this purpose but I have a screenshot for you. I am using my FTW2.o theme for this example.
Be creative with your CSS and post meta data arrangement. Good luck!
PreviousLate night rant
wahh, sekarang dah start experiment dgn php dah.
great.
gad, u’re the man!
creative2..
nice idea.
Cool ni flisterz.
Thanks, I’ve been wondering about this!
bro.. boleh bagi code tak untuk bezakan admin dengan user punya komen… tq
send kat my mail bole?
Very good idea. Thanks for this usefull tutorial!
cooll!!
So helpful.
Thanks!
I really like the layout and colors that you chose for this website! It certainly is incredible!
I like your website ,and like to communicate with everyone on this issue!
I love this site, so thank you
I don’t quite understand why people waste their time configuring/modding/editing WP themes and config files while you can create your own blog engine with a bit more knowledge in PHP/JSP/ASP scripting.
Create ‘your own Wordpress’ and do whatever the hell you want with it. Trust me, it’s more fun that way. Haha.
http://fr7ty.blogspot.com
I am specialized code for women and make everything new
The visit has added a lot of the code thing
Welcome
this is very nice but i bumped into a problem, how do you modify the text colors or even the size of the comments?
screenshot: http://img396.imageshack.us/img396/1633/helplw4.jpg
please help. thanks very much.
ap0kdhbtek56npc3
I enjoyed this site very much and have taken away a better insight. I will recommend this site to everyone I know. More people should step into .
dutasteride reviews
hello it is test. WinRAR provides the full RAR and ZIP file support, can decompress CAB, GZIP, ACE and other archive formats.
pxvqtflpjgzzrlofwbdkxebfmnzwkhcaxpbhello
Hey friends, Thank you !
This is a great page. And the contents are really that worth reading. I will add this to my own library
Useful stuff, well done!
More references in this would be greatly appreciated.
jackson,
createmlm.com
2]Get your own Nintendo Wii
The games console with one of the strangest names on the planet (it’s pronounced ‘wee’) is also one of the most innovative. In fact, with its potential to change the face of the gaming landscape, Wii may be on the verge of a new era, if you’ll pardon the pun.
The $400 Wii package comprises a square white console unit and stand that plugs into your TV or AV receiver, a wireless sensor bar that connects to the console and receives wireless commands from the battery-powered paddle-style Wiimote controller. Basic composite cables are supplied, but if you have a plasma or LCD the $50 component cable options will deliver better picture quality. The console also supports an SD slot, USB port and a DVD drive for games.
Games data can be saved to SD memory cards, which weren’t officially released at the time of publication, but in lieu of their arrival, GameCube memory cards will suffice. The USB port can’t be used to save games either, but will enable future hardware upgrades such as a hard drive or DVD player, although no announcements have been made to this effect.
Despite its DVD drive, the console is not a DVD player (a modification chip is required if you want to watch movies). Nor is it the high definition, hard drive-toting, networked multimedia online multiplayer gaming machine that is the Xbox 360 or forthcoming Playstation 3. Instead, it presents as the most affordable ‘next generation’ games machine available and, certainly, lacks for no important ingredients if you want to have fun.
This is great, but it also shows the comments on my About Us and Contact Us pages, which I don’t want to happen. Can I put another IF statement in the routine to check for the page its on? What do I check for (in fact where can I find a list of the variables/functions available in WP to use)?
Whew, I did a lot of searching and learned a lot. In the end, I was able to solve my own problem! To get the comments ONLY on the main page:
Just after:
I inserted this line:
Then just after the last
I inserted this line:
Now it shows the comments only on my home page!
Son of a gun! How was I to know I couldn’t put PHP code in a post!
Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language
See you!
Your, Raiul Baztepo
http://berdebah.mybrute.com
How can this be changes to show the whole comment – rather than just an excerpt?
@Denise Young: You can replace the
< ?php comment_excerpt(); ?>to< ?php comment_text(); ?>Thanks, I searched forever for this. I’m your newest fan.
This is a great piece of code!!
However, when the user clicks to add a new comment, or if the user goes to the specific post page, the comments are now shown twice because of the comments_template.php
Is there a way to modify this code so that it only displays on the home page?
I figured out on my own that if I add an if (is_home()) statement around the whole piece of code it works great!! Only displays this code on the homepage.
This is exactly what I was looking for, and found a link to your site in the WP forums. Thank you!
Great stuff; thanks very much.
Now I’d like to make the excerpt a link back to the full list of comments for the post…
Cheap Amoxil Online
This is especially important if you have any known allergies to other types of antibiotics.
thanks nice blog
I have put this script on my page, however it does not always show the latest comment when I refresh. Is there a reason for this?
At first it seemed like I had to have a comment in each post for the new comments in the NEWEST post to show up.
Now it just stopped showing recent comments for all my newest posts altogether, but it still shows the recent comments for the older ones…
Why is this?
Thanks for this information! I’ve been looking for this, and this was very helpful.
thank you for your article, this is the good information
I’m so glad I found this site…Keep up the good work
Great site. Thanks
Excellent tutorial dude…hits the spot!
Just a note to others, remember that if you have a home.php then you need to make these changes in there as well!
Hey, I found your blog in a new directory of blogs. I dont know how your blog came up, must have been a typo, anyway cool blog, I bookmarked you.
Just wanted to drop you a line to say, I enjoy reading your site. I thought about starting a blog myself but don’t have the time.
Oh well maybe one day….
We are a group of youths who run a non-profit, voluntary organization.
Is there any forum where we may learn about php scripts so that we may use it for our website.
Thanks for the blog post! We check often for tips and news…Keithhttp://www.eBuyHD.com
Learn about their population. ,
Although I am fully convinced of the truth of the views given in this volume, I by no means expect to convince experienced naturalists whose minds are stocked with a multitude of facts all viewed, during a long course of years, from a point of view directly opposite to mine. ,
[... - http://www.flisterz.com is another good place of advice. Making money online is [… -
thanks a lot, this post really helps!!!!
Hi
Can somebody explain how can I make visible post comment box in the homepage?
this is be cool
pthc incest ixefzm young little nude lolita 560466 family naturism preteen norxeo swimwear lolli klxuiy hairless preteen pussy idhmr underage sex movies %-D sandra model sex ascll ls magazine board 980998 gallview =-) naked kids playing %( hussyfan imgboard ycg little teen model gszcm guysex 9620 young nudist kids 554380 top kds sites rhyzz thailand underage
( naked lolitas brutal cock =( child porn search 8PPP loli gallery
ls magazine bbz 290 illegal teen girl porn %-) rapidshare tushyschool 8-))) free illegal very young virgin sex clips :]]] lol sites >:D hot kid sex =DDD child porn pics 1623 underage nude movies %-]] 565 tdz nude kids pictures rnytxv ls magazine hacked pages 816 sexfilimleri wpybf sweet nymphets
P nude preteen art arjg pedo pics ugh russian lolita porn >:OO underage nudist photos %(( preteen cp pthc nude naked illegal underage =-DDD preteen gymnastic pics tsl sexy underage filipino girls tbfkv pre teen model search
) hussyfan nudes 8-( lol facepunch qpogww domai blog lje sex porn teen child 8-]] nearly nude kids xlwqj lolita nudist =-))) very young girls underage dirty homemade cfeps ls magazine ls-island
P free lolita child sex video qhdlg young gay preteens 28827
Wonderfull great site underage nude movies bfp illegal girl preteen porn 8[[[ underage rape 972 underage girls pictures fshgm illegal verry young virgin teen hardcore sex galleries incest rape 9363 child pornography sites 09572 free preteen bbs
amanda fashion model 201 nuist krc underage sex pictures 691150 top sexy kds 8-D pedo pthc bbs cp hussyfan fdwyel preteen panties vids
no nude art preteen models zzdgm underaged kids naked gecj underage forbidden porn
( naturist models 8847 free underage kiddy porn pics >:P nude kids preteen kwlv bbs nymphets staze domai blog rvac naked gay children :[[ illegal verry young virgin teen hardcore sex galleries incest rape 028 cp pedo kds chill portal
5610 little child model 8DD naked care kids >:-((( bedavaporno memth dell latitude cp m233xt support drivers 99472 littleteens 0602 kds bbs pic bys naked in front of very young little virgin 20430 preteen models photos >:-D adult child sex 860 nude charming angels ls magazine digest >:PP child pornstar models gueffp kid sex pic %-DD hot naked kids 059583 shakeela4u pui small particle model %(( no nude pre teen 5867 no nude pre teen model 416161 can preteens have sex %-OO pedo porn underage chill kds baby rompl pics myc uncensored teen porn kypau models dieting tips 903 preteen underage girls vgxy asian preteen little girls eihapo petite naked very young japanese little virgin 385427 ls magazine issue %OOO hussyfan news wcair
Thanks for this, just what I was looking for.
Jaya