Brian’s Latest Comments
Like my plugins? Try my game!
If you like my plugins, maybe you'll like the popular game I made for PC and Mac (yes, shameless plug).
Try Deep Blue Sea - it's free (Download: PC | Mac)

Michael Heilemann suggested a different kind of "latest comments" to me, and I implemented them.
Brian's Latest Comments shows the latest activity on the website, as seen on the right hand side.
It has been tested to work with WordPress 1.5 and WordPress 2.0 with the default theme.
Installation
- Download brianslatestcomments.zip
- Unzip to your wp-content/plugins folder
- Activate from your plugin admin page
If you are upgrading from 1.1 to 1.2, please note that the new versions function arguments are a little different.
How to use
The plugin gives you a function called blc_latest_comment.
The simplest way of using it is to add this to your blog:
<ul class="latestactivity">
<?php blc_latest_comments(); ?>
</ul>
However, it does offer a bit of customizability.
The arguments the function accepts are these:
blc_latest_comments(number of posts, number of commenters per post, hide track/pingbacks, prefix, postfix, fade_old, range_in_days, newest_color, oldest_color)
- Number of posts
- The number of posts you want in the list. Default is 5.
- Number of commenters per post
- How many names you want to show under each post. Default is 6.
- Hide track/pingbacks
- Whether or not to hide pingbacks and trackbacks. Default is false.
- Prefix and postfix
- These are wrapped around each post and list of commenters. Default is
- and
. - Fade old
- Whether to use comment temperatures. Default is true.
- Range in days
- The number of days it takes for a comment to fade from the newest color to the oldest color. Default is 10 days.
- New color
- The color of a completely new post. The default is a dark gray.
- Old color
- The color of a post that is as old or older than the number of days given by the "range in days" argument. Default is light gray.
If you have Dunstan's Time Since installed, the links will have the title="" attribute set to a time since message.
If not, there is no title.
How to change the look
The way I achieve the look I have on my Activity on the right hand side, is by adding this CSS to wp-layout.css:
.latestactivity small
{
display: block;
margin: 0px;
margin-left: 10px;
font-size: 94%;
}
Bugs and limitations
For a current list of bugs and bug reporting, please go to the project page.
Support and discussion
Please use the project forums for support requests and discussion about the plugin.
I think that's about it. Happy latest commenting.
Great code! Thanks a bunch. Just a quick comment on your instructions for adding the CSS. In the php code, the UL has id="latestactivity" while the CSS snippet posted is a class; .latestactivity.
Ah! Thanks :) That was dumb of me, and a very common mistake.
So how is this fixed?
In other words, how do I make the posters names grey like yours?
You read the section called "How to change the look" and then you add the line:
color: #ccc;
Inside the {} brackets.
Thanks for the help. It's not working though. The posters are still blue.
http://www.sleightgeek.com
I'm sure I'm doing something stupid.
ah. Add another section like this:
.latestactivity small a
{
color: #ccc;
}
to your wp-layout.css – that should fix it.
Stupid question. Where is the wp-layout.css?
Yeah nice one
When I try to install your plugin, I get this error:
Database error: [Access denied for user: '<USER>@%' to database '<DATABASE>']
CREATE TEMPORARY TABLE tmp (comment_post_ID INT, comment_date DATETIME);
Database error: [Table 'tmp' was not locked with LOCK TABLES]
INSERT INTO tmp SELECT comment_post_ID, comment_date FROM wp_comments ORDER BY comment_date DESC;
Database error: [Table '<DATABASE>.tmp' doesn't exist]
SELECT comment_post_ID, post_title, ID, MAX(comment_date) AS f, UNIX_TIMESTAMP(MAX(comment_date)) AS unixdate FROM tmp, wp_posts WHERE comment_post_ID = ID GROUP BY comment_post_ID ORDER BY f DESC LIMIT 5;
Warning: Invalid argument supplied for foreach() in <PATHTOMYWEBLOG>/wp-content/plugins/brianslatestcomments.php on line 25
I think there is something wrong with global $wpdb->query in my installation. I use WP 1.2, maybe you know what the error is.
Oops, I removed the name of my DATABASE and USERNAME. I hope the code is still readable. :-/
What version of mysql are you using?
I'm using MySQL 4.0.1, my provider said.
Try downloading the newest version (I made a minor change) and see if it works now.
No, sorry. Still access denied. :-/
I haven't tested the plugin with WP1.2, I suddenly remember. But I think the problem is MySQL 4.0.1, not WP1.2.
I'll have to take a better look at it later. Probably tonight.
No problem. Thanks for your help!
I'm sorry to say this, but it works perfectly here with MySQL 4 as well.
I am thinking it might be because of your ISP has some kind of special configuration.
Any change you can ask your ISP whether they see anything offensive in the SQL query that their server is configured to prevent?
I'm using WP1.2, works great.
Brian,
A comment about your comments… :) I didn't realise that by default I would be subscribed to comments; may I suggest that the default be not to subscribe, or, at least moving the check box up by the email address field so that it is obvious? I'm lazy, and I didn't read past the end of this comment input text box to look at the subscription thing. Save us from our own laziness, Brian! :)
Also, cheers to you for the work you have shared with the WordPress community. It's much appreciated. You also have a great site. :)
Well… I prefer that people who leave me questions will be notified when I answer, and I figured that the people who were too lazy to see the checkbox were the same people who would forget to check back if I didn't send them email.
That coupled with the fact that Scriptygoddess' cool plugin has an unsubscribe link right there in the email led me the conclusion that I could get away with having it default to opt out.
If I do change it, it will probably be to having a cookied sticky state, so once you deselect subscription, it will stay like that.
I appreciate your nice words about my site and work. I am happy I can help :)
for some reason, my subscribe is not checke by default. am i doing something wrong. any help please
Excellent plugin, just what I was looking for, many thanks.
Bizarrely I have a quote mark (') in the title of an entry on my blog, which appears normally in my local version, but has a slash in front on the full site? Given that, I presume that it is to do with my isp's server, but is it possible to add stripslashes in to the plugin? It would negate the need for me to contact the ISP.
It has a stripslashes on the names of the posters.
You want one in the post title as well?
That would be lovely. If it's just a matter of adding stripslashes in the correct place, then I really should stop being lazy and using other peoples plugins left right and centre and write (and alter) my own.
But yours are so nice and just what I want. :-)
This is a very geeky conversation, which I don't want to do right now.
Hi!
I just installed this plugin, but I get the following output on the page:
Database error: [Access denied for user: 'higgsfamily@localhost' to database 'higgsfamily']
LOCK TABLES wp_comments WRITE, tmp WRITE
Following that are some posts with comments mentioned… Any idea on what would be causing this?
Thanks a lot!
I suspect it's because your database user don't have priviledges to lock tables.
Is it your own server or an ISPs?
My site is hosted by another company (so not by me or my ISP). So obviously, I don't have the ability to change the privileges of the user. Is it possible to run the plugin properly without having the privilege to LOCK tables?
Thanks!
Unfortunately not.
You could try to remove the two lines of code that does the lock and unlock, and see if it still works.
Hi!
It seems to work OK without the two LOCK/UNLOCK lines… I just have to fix up the CSS now.
Thanks!
That's good.
There is a theoretic possibility that this can be a problem, but unless your site is hammered like google, I don't think it should cause any problems that those two lines are missing.
Even if they are, the worst that can happen is that someones comment posting goes awry.
I too am getting database errors, and lock/unlock delete didn't work. Here is the error:
Database error: [Access denied for user: 'username' to database 'dbname']
CREATE TEMPORARY TABLE tmp (comment_post_ID INT, comment_date DATETIME);
Database error: [Table 'dbname.tmp' doesn't exist]
INSERT INTO tmp SELECT comment_post_ID, comment_date FROM wp_comments WHERE comment_approved = '1' ORDER BY comment_date DESC;
Database error: [Table 'dbname.tmp' doesn't exist]
SELECT comment_post_ID, post_title, ID, MAX AS f, UNIX_TIMESTAMP(MAX) AS unixdate FROM tmp, wp_posts WHERE comment_post_ID = ID GROUP BY comment_post_ID ORDER BY f DESC LIMIT 5;
I've deleted the username/dbname in this comment, but you get the idea.
It means that your database user doesn't have the correct privilege to create a temporary table.
There is no solution to this problem that I know of.
I will probably make the plugin so it fails more gracefully, but right off the bat, I can't think how I would solve this even halfway gracefully with no subqueries and no temporary tables.
That's unfortunate! I'll take it up with my host. I have definitely given myself all of the priveledges they let me give myself (about 10). Thanks
Problem corrected. :)
Great! :) Glad you got it working.
I've deployed this plugin now, and all works nice.
I have one suggestion though, and that is regarding the order at which latest commenters are shown. Currently, it shows latest commenter to a post, on the left side of the list of commenters. Following this is the second-last, etc.
I find this illogical, as this is the opposite direction as to how the comments are actually being shown… that is, the latest post being bottom-most.
I would prefer the ability to show the latest commenter as the last of the list of recent commenters.
I hope I'm making sense—perhaps you can make this an option?
I suppose this option would be nice for some, but I don't think it's illogical. The idea is to show recent activity, so you'd want the most recent to be first.
Well, if the purpose is to highlight recent activity, then why not only show one commenter?
My point is, that no matter what your configuration, the most recent commenter will be shown. My beef is that the most recent commenter is shown first, when it is shown last on the page commented (providing you're not using threaded comments ;) )
I just find it illogical but I can understand why you'd feel otherwise. As such, I would be more than happy if it could be made an option (i.e. attribute).
I'm getting this error…Have you had anyone else who has had the same problem? Is there a way to fix this?
Warning: Invalid argument supplied for foreach() in /home/swanson/public_html/wp-content/plugins/brianslatestcomments.php on line 28
thanks!
Aren't there any more details?
Do you have any comments at all on your blog?
Hello ,
Love the activity plugin. Can someone help me. On my site hornbag.net the activity list has rather large gaps in between each activity. I really like the layout of binarybonsai.com and how the activity list is nice and neat. I'm guessing this is a CSS thing? Ig someone can help me out that would be great!
Many Thanks
Did you figure it out?
I just looked at your site, and it looks just fine.
Hey,
I did, I tried to reply to the post own your site, but was having problems posting.
The reason it wasn't working was because I didn't have any comments… :-)
So I left a "test" comment and bingo…it worked just fine :-)
Thanks, it's a great plug-in…!
Jeff
http://www.jeffswanson.com
Brian, just a brief heads-up, your comments plugin is fantastic, I really like it and have implemented it on my site. Thanks very much.
dave.
http://tcal.net/
I am glad you like it. Thanks for the heads up – it's always nice to see how people set it up, so you can blatantly rip off their good ideas :)
I'm getting my single and double quotes converted into slashes all over the place. I love the layout of this plugin, so i'm using it anyway, but in comment author, and post title i get a lot of slash/s.
i looked at the plug's code, and found where it seems to be trying to strip slashes from the comment author, but not from the title.
any chance you would share with us (me) what code should be added to strip them from the title as well?
regardless, thank you for the nice plugin!
F.
solved:
thanks to alphaoid from wp/support i did the following:
in the plugin itself find:
$comment->post_title
and replace it with:
stripslashes( $comment->post_title )
and the slashes are stripped from the titles.
it's like magic!
I'm glad you figured it out. I guess being too busy to answer promptly is paying off for me. People are figuring out all kinds of things :)
I would have done it the same way, so I can't say I disagree with your findings.
I'm getting this error after install this plugin and insert the code into my blog. Am I doing something wrong?
Warning: Invalid argument supplied for foreach() in /home2/shawng77/public_html/testblog/wp-content/plugins/brianslatestcomments.php on line 29Any help would be appreciated.
Please excuse the above post, I got it working.
I do however have a .php question though. How do I add the arguements listed above? I have no clue about coding .php or how to use the arguements.
What are you trying to do?
Well I'm trying to get what I have to look and act as you have it above, here is what mine looks like here: http://www.hexfactor.com/testblog
As you can see, the "1" is also a link and is not surrounded by ( ) and yours is not. How can I make the # of posts not act as a link and surround it by the ( )?
What do you want the number with () around to link to?
See thats the thing, I didn't want it to link to anything. I got a hold of one of the earlier versions of the plug-in before you implemented that and I'm now a happy camper. I just think its a bit redundant to have the number of comments a link then to also have the link included with the recent posters that links to the same thing. The old way just looks a lot cleaner IMO. Nice work on the plug-in Brian.
Thanks.
I actually didn't know that it linked the number to the posts now. I can't remember doing it. Maybe it's something Michael changed.
He was the one who fixed up this version.
I'll ask him when I see him.
Hi, I'm also wondering how to use the arguments. I want to reduce the number of commenters shown so it looks nicer in my sidebar. I'm new to wordpress and PHP. Thanks for the plugin!
You're welcome. The above documentation should explain how to do what you are asking for – it's the second argument to the function.
Shawn,
I see you've fixed the comment count, so that it shows up surrounded in ()'s. Can anyone confrim how this is done please? It's more assthetically pleaseing and makes more sense than a link'd number stuck out to one side.
open the plugin's php file… find this line (for me, it's line #46):
echo $prefix."<a href="".$link.""$title class="activityentry">".stripslashes($comment->post_title). "</a> <a href="$link#comments" title="Go to the comments of this entry">".$count."</a><br />n";
change it to:
echo $prefix."<a href="".$link.""$title class="activityentry">".stripslashes($comment->post_title). "</a> <a href="$link#comments" title="Go to the comments of this entry">"(".$count.")</a><br />n";
hope that helps (and hope this post shows up correctly :))
d'oh… here's my line 46.
sorry about the botched first attempt.
Bingo.
Thanks. I had started to look at the code, then checked back here before I started "playing" :)
Works a treat. Definately more asthetically pleasing.
Thank you for helping each other when I don't have the time.
I will incorporate this change into the plugin as soon as I have time.
Hi, I just installed the plugin and am using it on WP 1.2.1 and I keep getting the following error:
Database error: [Unknown column 'comment_type' in 'where clause']
INSERT INTO tmp SELECT comment_post_ID, comment_date FROM wp_comments WHERE comment_approved = '1' AND comment_type NOT LIKE '%pingback%' AND comment_type NOT LIKE '%trackback%' ORDER BY comment_date DESC;
Warning: Invalid argument supplied for foreach() in /rsalvi/rehanalvi.com/www/blog/wp-content/plugins/brianslatestcomments.php on line 29
Anyone know whats going on? Or what I could do to solve it? I'm having my site hosted; I'm not hosting it from my own box. Thanks.
Your database user doesn't have the necessary permissions to create temporary tables.
I need to get a proper error message in there for this.
The only fix I can suggest is to ask for the right permission from whoever is hosting your site.
Brian,
Do you know what exactly I would ask my hosting provider to do? Just upgarde permissions on MySQL? Something more specific? I know right now that I don't have rights to create new databases—I have to go through them for that—is that what the problem is or is there something more specific that I need to request from them?
Brian,
What exactly should I tell my hosting provider to do to let me make this plugin work? Do I just need to say "make it so I can create temporary tables"? Or do I have to tell them something different? Something more specific maybe? I don't know anything about this stuff since I'm a complete newbie, and anything you could provide more in details for what I should tell or ask them would be great! Thank you.
I think that's pretty much what you should ask them – something like "is is possible to grant my database user to create temporary tables?".
brians latest comments have been updated to WP1.5 and now use a different approach that should fix the problems people have been having.
hey brian,
just wondering how i can alter your code to only show the commentors names that are on that post withthe word thank you. eachcommentor's name would still link to their comment…just want each posttoshow each commentors…and not the "latest" lol, comments made
Great plugin, had a bit of problem with the fonts but sorted out.
Very nice plugin.
The only issue I'm seeing is that the "time_since" function is returning completely incorrect information. It shows 35 years ago for a comment made earlier today!!
(I commented out the function in the plugin to stop that)
MySQL 4.1 on Ubuntu
Thanks
Michele
Thank you.
I know of the problem for time_since.
I have yet to fix it, but it has been there for a while. I am not sure if it's my problem or if it's with time_since.
Thanks for making "Brian’s Latest Comments" available. It is a great plugin! Easy to use, easy to install and looks good.
richard
I wholeheartedly second (or is it Nth – where N is a very large number ;) ) that… thanks a lot for this plugin, I've added a link to it from my page!
New version of latest comments available.
A few bugs with the comment temperature were squashed and the version number upgraded to 1.5.7.
Hi, why nobody responds me?
Responds to what more precisely?
my problem is:
Fatal error: Call to undefined function: blc_latest_comments() in /home/eprofes/public_html/blog/wp-content/themes/connections/footer.php on line 23
I am guessing you forgot to activate the plugin from the plugin panel.
I installed the latest plugin and also have WP-Morph installed. It seems the two plugins don't play well together. So, I disabled the threaded comments plugin as not having spam is more important to me than having treaded comments :( However, when people attempt to post a comment, they now get the message: "It looks like the website administrator hasn't activated the Brians Threaded Comments plugin from the plugin page" This message appears weather or not the plugin is installed or activated. What is causing this?
You need to replace your old comments.php.
Brian, thankyou for the time put into this plugin. I'm using it now with K2 and Paul S's Deviance theme(s) on Dev Dawn. Testing as we speak.
It's very cool! But it seems can't show the comments of page ? I open a page as a guest book,so I want to see the comments of page. how can I do that? thanks!
It should do that by default if you used the files included with the plugin.
thanks, could you tell me some way to let it show the comments of page ? thanks!
I had the same problem with the foreach() function as Jeff Swanson but worked fine after posting a test comment.
Nice plugin, thanks a lot!
Could you tell me how to set the post number?
Ie when I use your instrcutre and enter 3, it doesnt work.s
can you show me what it would like?
Great Plugin! Love ThreadedComments too!
Hi! Thank you for the plugin, is great!
I have 2 question2: how can I exclude myself from the listing?
And how can I change the font size of the commenters?
Thanks again!
ok, i figured out the first one, just add:
AND comment_author_email != 'YOUREMAIL' in the $commenters variable… or define another variable and then put it there too.
Ok I can't seem to get the colors to change and I thought I didn't everything I needed to. Can you tell me what I did wrong in my style sheet?
http://www.fragilemusings.net/wp-content/themes/thirteen/style.css
Hey, could you take at my site :
guistyles.com
YOur plugin is on sidebar but it doesn't look good.
.latestactivity
{
display: block;
margin: 0px;
font-size: 94%;
}
Also i have question about that :
" Your Comment (smaller size | larger size) "
and " Subscribe to comments via email "
What plugin you use, it is great :)
The plugin is not compatible with FeedWordpress. If both enabled, the URL comments in BLC are totally wrong. :(
version 1.5.8: There is a small bug in the number of posts parameter. The number of posts displayed is 1 more than the specified value.
On line 91, I changed
if($num++ > $num_posts)toif(++$num > $num_posts).stupid question, but just Where in my blog do I put that line of code?
bah never mind i was thinking it was another version of nested comments…the latest doesn't seem to work my my layout at all, but i fugured this out and it's very cool too.
Can anyone tell me how to put the number of posts in between parenthesies like this-> (10) or like on http://becarry.com .
Thanks :)
WP 2 allows / creates pages for uploaded pictures. Those pictures can be commented on too, but the plugin doesn't show these comments. Any idea, what to do, to get these comments shown as well?
No idea – but I'll see if I can get it to work for BLC 2.0.
Wonderful plugin!
May I suggest that you change line four to read:
Plugin URI: http://meidell.dk/archives/2004/09/12/brians-latest-comments/This would make it that much easier for users to come upon relevant information via the wordpress admin.
OK, I must be missing something painfully obvious. I uploaded the plugin to my plugins sub-dir. visited the plugin manager. activated the plugin. visited blog. no change.
http://www.grandcanyonhiker.com/blog/
should recent comments appear automatically in my sidebar … or is there a code snippet i need to insert? please decloud me. thx!
You need to insert code. I think it's described in the install.txt.
thx. i figured that once the installation steps were cleared, the plug-in would work. obviously not. working now. thx for a great add-in!
Hate to be a bother. I love this plugin, but is there any easy way to not display the commenters names in the list? I'd really like to just have the link to the recently commented post (and it's comments as a whole). I tried a few things, but I'm clueless, so none of them worked.
Thanks in advance for any help provided. :)
Comment out line 126, 128 and 129.
Thanks so much! That did the trick! :)
Will you be working on making the threaded comment's also compatible with K2? Thanks for the great code, by the way.
Yes I will. You are welcome.
Time is scarce, but I will get it to work asap.
Thank you soo much… waiting in anticipation!
I'm still somewhat php-ignorant, so I'm probably doing something wrong, but I put the indicated code in place and what appeared instead of the comments was (less-than sign) ul class="latestactivity">
I get this error when I move the plugin call to the footer:
Fatal error: Cannot redeclare clamp() (previously declared in /home/xxx/public_html/wp-content/plugins/brianslatestcomments.php:27) in /home/xxx/public_html/wp-content/plugins/brianslatestcomments.php on line 27
Any idea on how to fix this? Or is this plugin simply a sidebar plugin?
Download the new version 1.5.9 – I just made some extra precautions that should fix your problem.
Brian, I love your plug-in – it's exactly what I was looking for. But I would like to know how to put parentheses around the comment count beside the post title. I read Shawn's comments above but couldn't quite work out exactly where to put the brackets on line 46. Any help appreciated.
Brian. I hope you don't mind, I've adapted your latest comments plugin to function as a Joomla Module for the Joomla component JD-WordPress. It's taken a fair bit of work to get it functioning correctly.
My website is http://www.zerolight.co.uk and you'll find it in the downloads section if you want to check it out. I've obviously given you credit for producing the original code. Mines a somewhat simplified version needed to work in Joomla.
Regards,
Graham
I am using WP 2.0.1
I have called the function from the sidebar and I get this on the website:
Comments
RSS
Fatal error: Cannot redeclare get_channel() (previously declared in c:program fileseasyphp1-8wwwwordpresswp-contentpluginsbrianslatestcommentsbrianslatestcomments.php:36) in c:program fileseasyphp1-8wwwwordpresswp-contentpluginsbrianslatestcommentsbrianslatestcomments.php on line 36
I am also getting this same error using blc 1.5.10 on wp 2.0.3
Trying to figure out where else this function is being declared and scratching my head a lot.
no problem anymore, I just found out that the theme I was using was already calling the function. BTW: the theme is K2
Ah yes – work needs to be done before it's k2 compatible :)
could you let me know what you removed and where? I am getting the same error
You should only call the function once at a time.
I think you call it 2 times or more :)
Maybe on a post and at the sidebar.
How did you get it to work with K2? I'd really like to know as I have the same error.
How are you supposed to change the colors? I've tried putting in the color inside the function, but nothing is working. Perhaps actually showing the function in use (ie.
) would be more helpful to some than just putting what you have up there.This is a really cool feature lacking in most professional themes. Thanks for the implementation!
Hi there. Great plugin. Just wanted to say that i had to show source code on this page to see what code could be inserted in sidebar.php in order to show you plugin. I use firefox on PC.
Hi, im having a little problem:
I dont have any comments yet in any of my posts, and i get this error:
Warning: Invalid argument supplied for foreach() in /usr/home/users/5a/juglar/www/www.slcblog.com.ar/wp-content/plugins/brianslatestcomments.php on line 87
And if i post a comment doesnt appear, so its fixed.
how can fix that?
Btw: nice plug in!
well I'd the same here so I just decided to put an if statement before the foreach so if there's no comments it just says No comments.
just copy this code to a text editor and name it "brianslatestcomments.php" then upload it to your server in the wp-contents/plugins folder (NOTICE! it will replace the old file so make backup before)
Michael Heilemann</a>.If you have <a href="http://binarybonsai.com/archives/2004/08/17/time-since-plugin/" rel="nofollow">Dunstan's Time Since</a> installed, this plugin uses it for the title="" attributes on the comments and posts. (For WordPress 1.5)
Author: Brian Meidell
Author URI: http://meidell.dk/blog
Version 1.5: Now works without LOCK TABLE and CREATE TEMPORARY TABLE priviledges.
Version 1.5.1: Can't remember what I did here
Version 1.5.2: Fixed count select statement to not include spammy comments
Version 1.5.3: Properly excludes track- and pingbacks
Version 1.5.4: Excludes posts that are not published, even if they have comments
Version 1.5.5:Fade old comments, fixed bug that wreaked havoc with Time Since
Version 1.5.6:Bugfix from Jonas Rabbe (http://www.jonas.rabbe.com/) pertaining to timesince
Version 1.5.7:Bugfix so old colors can be darker than new colors (stupid oversight), thanks to http://spiri.dk for spotting it.
Bugfix where single digit hex would cause invalid colors, thanks to http://www.wereldkeuken.be/ for the fix.
Version 1.5.8:Bugfix from Matthias Schutz regarding time_since.
Version 1.5.9: Added function redefiniotion protection if people use the plugin in several places
*/
function blc_latest_comments($num_posts = 5, $num_comments = 6, $hide_pingbacks_and_trackbacks = true, $prefix = "", $postfix = "", $fade_old = true, $range_in_days = 10, $new_col = "#444444", $old_col = "#cccccc")
{
global $wpdb, $tablecomments, $tableposts;
if(!function_exists('blc_clamp'))
{
function blc_clamp($min, $max, $val)
{
return max($min,min($max,$val));
}
}
function get_channel($col, $offset)
{
return hexdec(substr($col, $offset, 2));
}
function channels($col)
{
$r = get_channel($col, 1);
$g = get_channel($col, 3);
$b = get_channel($col, 5);
return array($r, $g, $b);
}
$max_time = $range_in_days * 24 * 60 * 60 ;
function scale_channel($old, $new, $diff, $max_time)
{
$range = $old - $new;
$c = round($diff/$max_time*($range))+$new;
$c = blc_clamp(min($new, $old), max($new, $old), $c);
$c_hex = str_pad(dechex($c), 2, '0', STR_PAD_LEFT);
return $c_hex;
}
$usetimesince = function_exists('time_since'); // Work nicely with Dunstan's Time Since plugin (adapted by Michael Heilemann)
// This is compensating for the lack of subqueries in mysql 3.x
// The approach used in previous versions needed the user to
// have database lock and create tmp table priviledges.
// This uses more queries and manual DISTINCT code, but it works with just select privs.
if(!$hide_pingbacks_and_trackbacks)
$ping = "";
else
$ping = "AND comment_type'pingback' AND comment_type'trackback'";
$posts = $wpdb->get_results("SELECT
comment_post_ID, post_title
FROM ($tablecomments LEFT JOIN $tableposts ON (comment_post_ID = ID))
WHERE comment_approved = '1'
AND $tableposts.post_status='publish'
$ping
ORDER BY comment_date DESC;");
$seen = array();
$num = 0;
if($fade_old)
{
list($r_new, $g_new, $b_new) = channels($new_col);
list($r_old, $g_old, $b_old) = channels($old_col);
}
if ($posts > 0)
{
foreach($posts as $post)
{
// The following 5 lines is a manual DISTINCT and LIMIT,
// since mysql 3.x doesn't allow you to control which way a DISTINCT
// select merges multiple entries.
if(array_key_exists($post->comment_post_ID, $seen))
continue;
$seen[$post->comment_post_ID] = true;
if($num++ > $num_posts)
break;
$commenters = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(comment_date) AS unixdate FROM $tablecomments
WHERE comment_approved = '1'
AND comment_post_ID = '".$post->comment_post_ID."'
$ping
ORDER BY comment_date DESC
LIMIT $num_comments;");
$count = $wpdb->get_var("SELECT COUNT(comment_ID) AS c FROM $tablecomments WHERE comment_post_ID = $post->comment_post_ID AND comment_approved = '1' ".$ping);
$i = 0;
$link = get_permalink($post->comment_post_ID);
if($usetimesince)
$title = " title="Last comment was ".time_since($commenters[0]->unixdate)." ago"";
else
$title = "";
echo $prefix."<a>".stripslashes($post->post_title). "</a> <a>".$count."</a>n";
foreach($commenters as $commenter)
{
if($usetimesince)
$title = " title="Posted ".time_since($commenter->unixdate)." ago"";
if($fade_old)
{
$diff = time() - $commenter->unixdate;
$r_hex = scale_channel($r_old, $r_new, $diff, $max_time);
$g_hex = scale_channel($g_old, $g_new, $diff, $max_time);
$b_hex = scale_channel($b_old, $b_new, $diff, $max_time);
$colstr = " style="color: #".$r_hex.$g_hex.$b_hex.";"";
}
if($i++ > 0)
echo ", ";
echo "<a>comment_ID.""$title>".stripslashes($commenter->comment_author)."</a>";
}
if($count > $num_comments)
echo " <a>[...]</a>";
echo "".$postfix."n";
}
}else {echo "No comments";}
}
?>
hope this helps!
BTW thanks brian nice plugin!
First: as a longtime WordPress user (nearly four weeks) I am delighted to find this plugin, which fills one need I had. My blog doesn't have many posts; the posts are family stories that people share. So I wanted folks to be able to find the most recent comments.
If I understand what Wayann is saying, the code here would show the latest posts whether they had comments or not, and then show the commenters for those posts in the list that had them. Is that correct?
That would be a great help. Most people coming to my site don't read blogs, and so I want to make the site trouble-free for them.
The site is: http://www.cousinagamfhein.net
This is one story that justified all the work I've put into the site thus far—how my uncle Freddie learned what his name was.
http://www.cousinagamfhein.net/wordpress/2006/02/08/how-freddie-macdonald-learned-his-name/
Hey Brian,
Just a request. On the next update, could you add the < ?php rather than only to the plugin since someserver_ doesn't support short PHP tag.
Thanks.
Done. It will be in the next release.
A very nice plugin, but (like Stephan) I had to look into the sourcecode of this page to see the code to be embedded.
Cheers from Germany, Harry
I have install the plugin. But i don't understand how i can put it in myne sidebar… I want to see the topic and the numbers of reply (topcicname (replay's). Can some help me with this…
Greetings from the Netherlands,
Eddie
Eddie:
I'm just a beginner, but what I did was to add a new section to sidebar.php…
Right now I'm simply using the defaults. My post titles are long, but that's not the plugin's fault:
http://www.cousinagamfhein.net
Hello. I installed this plugin on WP 1.5.1. I already activated the plugin, and added this line:
","",true,10,"#888","#fafafa"); ?>But, I keep getting this message in my homepage:
Fatal error: Call to undefined function: blc_latest_comment() in /srv/oracle/iasprod/Apache/htdocs/ap/gilog/wp-content/themes/jdBusiness/sidebar.php on line 64
How can I fix this?
I am trying to change the oldest color fucnction and I am trying this way:
But the Hex Number shows up ..I am a newb 8 ( any help would be greatly appreciated
ARGH
show code darn U!!
I give up I can't paste the code
Hey Brian, awesome plugin, but it doesn't play with the favatars plugin—they both try to set the comment image. Can you code a workaround and/or get in touch with the favatars guys?
Thanks
Hi, first of all great plugin. I made some small formating changes with it to just show a post title and # of comments…like some other people here did. I could then get the code below work fine on the index.php page with the default Wordpress 2 skin.
However if I placed it in the sidebar.php the function would not produce anything. Any thought?
Man the damned time_since code gives me trouble. I can't seem to figure out why, but something with the plugin is messed up and I endup getting the comment to be post "-1 years and 12 months ago"?? (It's actually been posted a few minutes ago).
Me likey this no-brainer plugin, thx Brian.
I gotta admit, if I could get my comments setup like http://www.thinklemon.com/ I would be set. I haven't figured out the parameters for this plugin yet but the CSS isn't the problem. I tried not showing myself also but those line numbers don't match in my just downloaded version so it's still a guessing game without the parameters listed anywhere. I bet if they were laid out in the beginning, this whole thread would be full of nothing but accolades, to the original author of course lol.
yes I know they are laid out, just no usage example (which is what I meant), look at all those people with no answer, basically being slapped in the face, shame shame.
@BillyG: I'm using http://blog.jodies.de/archiv/2004/11/13/recent-comments/
I have no experience with 'Brians latest comments', yet. So I cannot give an informed comment. I just installed and have it running for some time now.
hi there, thx 4 this great plugin, exactly this waht i was looking for :)
have got a question, i would like to add a pic to the output on the sidebar. u are using an pink arrow ( think this is for entries )
how can i configure your plugin and add a different pic, perhaps a talking icon or a smiley instead?
thx 4 answering and your time, greets from austria
brian, how to change the fading color? because i have a black background.
I have installed your plugin but an new to all this. Nothing changed on my wordpress home page. How do I get this plugin to appear on my sidebar. Is there something more I need to do? Could you email me back on this one?
Hey Brian,
Your "Brians Latest Comments" script was giving me a warning when I didn't have any comments in my blog, I just tweak it a little so the error didn't show up. Hope this can be useful to someone else.
You can find the file here.
The URL in the plugin config (ie. the link from wp-admin/plugins.php) is incorrect. It's currently set to:
http://meidell/latestcomments/
Hi Brian!!
I got the same messege as Swanson ((Warning: Invalid argument supplied for foreach() in /home/swanson/public_html/wp-content/plugins/brianslatestcomments.php on line 28))
BUT i solved the problem. (But first after using some 3 hours mucking with the php file {IT DIDNT WORK} then back here and read all these coments trough. And i find it finally You need a just one comment on a radnom site and vupti!.. I am totally Newbie and i would wish for others you maybe would highlight this error and its solution for others!)
Just a little dont worry note where you download the plugin ore a read me file in the download!!
All best alex!
Hi,
I've got the same problem with line 89. The solution is to add this line before the foreach statement
if (!$posts) return;The foreach statement wants to have an array $posts as argument but if no comments available, $posts is empty. With the if statement you check for an empty $posts var. Hope that helps.
It is a very nice plugin! Thx! Markus
What is the line of code I'm supposed to add to my sidebar?
I am having trouble using this plugin. I could not install it in the sidebar.php so I tried just trying to install it on a static page with a link from the sidebar. Can you show me how to imbed it in a static page?
With respect to the difficulties I am having in the sidebar, I suspect it is because I am using a "non-standard" theme. My theme is tiga-06 and the sidebar.php looks like this:
get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories");
foreach ($link_cats as $link_cat) {
if (get_links($link_cat->cat_id, '', '', '', FALSE, '', FALSE, FALSE, -1, FALSE, FALSE)) {
?>
cat_name; ?>
cat_id); ?>
',''); ?>
<a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional" rel="nofollow">Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a>
<a href="http://gmpg.org/xfn/" rel="nofollow"><abbr title="XHTML Friends Network">XFN</abbr></a>
<a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform." rel="nofollow">WordPress</a>
Can someone give me a clue?
I just hacked a small bugfix release v1.5.11 for this plugin, coz your latest 1.5.10 won't work with WordPress 2.1, due to changes in the wpdb class structure.
Infos and Download at http://www.4null4.de/167/bugfix-for-brians-latest-comments/
I just need to code that goes in the sidebar, it isn't shown above that I can see. All I can see is
"The simplest way of using it is to add this to your blog:
However, it does offer a bit of customizability.
The arguments the function accepts are these:"
Sorry. That was my stupid mistake. I hadn't taken into account that the browser wouldn't show it.
I fixed it.
never mind i ad-libbed and it works.
I've patched the plugin to add full support for AJAX Enhanced Paged Comments in Binary Blue, which enables the plugin to directly switch to the appropriate comment page if a user hits a comment author link. This integrates as well very smmothly with the Sidebar Widget for BLC that I've written some time ago as well.
Your Plugin do not work if there's no comment posted in the blog. I think it's no big deal, but I wonder, because I got an error because of this. However, great plugin. Thanks a lot…
Bye
I don't know why, but every time I try to load this page in Firefox 1.5 (OS X), it freezes up the browser, with the status bar saying it's in the middle of loading something from Google Analytics. :( I don't know if I'm the only one having this problem but I thought I would mention it in case I'm not.
Hi Brian, I've just found your excellent plugin from a good friend Shiv, the only thing I don't understand how to do, not being a php person is how to add a line after each post/comment set. Your page looks good with it, because its got a wider sidebar, mine being thinner would look better with a line after a post/comment block. Any ideas on how to achieve this? Thanks
I'm trying to customize using blc_latest_comments(10,5,true,,,true,7,"#A13310","#CF6029");
but it gives me: Parse error: syntax error, unexpected ',' in …
Something I'm missing?
Ich hatte die Einstellung von 3 plugins gestern und nur 1 link ich eine unsatisfied Armando Gueco Spitze durchgeführt
Edde:
Maybe need use format whithout '#' symbol in color?
Thanks for this great plugin
Hi Brian,
I am using your latest comments plugin 1.5.1.0, WP 2.0.4, and the new fresh theme just released. If click the latest comment link on the front page sidebar I get sent to a random and incorrect website, but the latest comments link is perfect when I click while reading the post associated with the comment. Any Ideas?
http://www.sbe38.org
don (el paso)
My problem is caused by the "feedwordpress" plugin. Any suggestions why the two don't work well together?
Thanks for this plugin… it's really nice, and useful
:)
I'm trying to put the plugin to work in a blog I'm designing but it keeps breaking the template! It was fine on a new install but broke at some point while I was uploading the old posts. Any ideas?
Thanx for a great plugin! Works perfectly.
Hi – I just got your plugin, and am excited to use it. I am trying to take the four lines that call the plugin and put them in sidebar.php, but I don't know where to put them in the code. Wherever I've tried, the sidebar breaks. Most sections seem to have and surrounding them – I've tried the four lines with and without the lines, but neither work. Can someone tell me where to place the code? Thanks.
Gene
To make it WordPress 2.1.x (and maybe 2.0.x?) compatible, just change all the $table* ($tablecomments etc.) to $wpdb->* ($wpdb->comments).
I'm having problems with the googlecode.com download-link as it doesn't contain any files for download. Hope somebody can help me out.
It works for me.
Hi Brian
On http://code.google.com/p/brianslatestcomments/downloads/list, it still just says that "This project currently has no downloads". Am I on the wrong track here? Could you please post the link that you've got working? Thanks a lot.
Ah, that explains it – I think the downloads page is a new thing since I started using google code (or I am blind) – the files are in the svn tree:
http://brianslatestcomments.googlecode.com/svn/trunk/
Just get the zip file :)
I'll see what I can do about putting something under downloads :)
Hi Brian,
I downloaded and added your latest comments plugin to my site, however the display of it in my right sidebar does not work. Instead of listening the latest comments horziontally, it lists them vertically. for example:
Title of post
No. of comments
author1
author2
author3
Instead of:
Title of post No. of comments
Author 1, Author 2, Author 3, etc.
Can you tell me what the problem might be? I've adjusted the sidebar margins, but that doesn't seem to work. Please let me know what the problem may be. I'd really appreciate your help.
Thanks
It is most likely because you have some CSS styles on your site that also get applied to the latest comments.
My guess is you might have something like like "display: block" for li elements.
It's a really usefool pluging which I ever used. Really!
Hi Brian!
First of all thank you for this great plugin, I'm using it for… years :-) now!
I've got one question: would it be possible to cover multiple wordpress-installations in one db? So that the latest 10 commented postings from all blogs in that db are shown? That would be awesome!
Thank you!
Daniel