yeah it works! with some match things of course ^_^
yeah it works! with some match things of course ^_^
nice!
Nice ! I added the author and post title myself.
Now has it's own Wiki page...
http://wiki.wordpress.org/index.php/Recent%20Comments
Can anyone help a novice like myself tweak the output of this. I'd like a little exerpt of the comment followed by 3 elipses and then "(g0)" linked with the link for the entry. Unfortunately I'm still learning PHP so I have no clue how to tweak it so my output looks different.
Thanks,
Daisyhead
Look for the two lines toward the end of the function that begin with "$output .= ". These are the lines that create the line with the comment author's name and the comment excerpt linked to the entry. You can modify them as you see fit. If you have questions, don't hesitate to ask.
Thanks! I'm still having problems with tweaking it, but I'm going to try tomorrow when I'm not so freaking tired.
-Daisyhead
Will this skip over the comments in a private, protected post?
Yes, the updates I made the other day should make it work similar to the recent posts hack, except for the fact that there isn't an option to skip posts...but I don't see a need for that.
SG,
I've updated this hack and it should work like the others now as far as only showing published posts that don't have a password (by default).
Okay, I must be stupid, but I'm having a hard time formatting the output of this. I would like it so that it lists an exerpt of the comment, which it does, but instead of having that excerpt being the link, I'd like this (go) added and that to be the link to the comment. Make sense? I'm sure once I see how the modifications are made, I'll understand but I'm not having much luck today.
Thanks,
Daisyhead
I think I just figured it out! Yay!! =)
Looks like you beat me to it!! :-P
very nice hack! I couldnt find a way to write the title of the commented post to the output. Any hints are welcome 8-)
Thanks!
Add post_title to the SELECT portion of the query and then add $comment->post_title to the $output .= line where you would like the title to be displayed. Post back if you have questions or run into problems.
It's printing "$comment..." because you have it inside the single quotes. It has to be moved outside of the quotations.
I am trying to make one last tweak to this hack. I want the comment author link to show up, linked to the comment author's name and then the excerpt of the comment to follow. I've added the following line:
$comment_author_url = stripslashes($comment->comment_author_url);
And for my output I have:
$output .= $before . '' . $comment_author . ': ' . $comment_excerpt.'...
$output .= '" title="View the entire comment by ' . $comment_author.'">' . (read).'' . $after;
And while a link is showing up, it's not the link to the comment author's page. Any ideas on how I can fix this?
Thanks,
Daisyhead
Where are you placing this line?
$comment_author_url = stripslashes($comment->comment_author_url);
It needs to be inside the foreach portion of the function.
I'm placing it under this line:
foreach ($comments as $comment)
This is what the whole thing looks like:
function get_recent_comments($no_comments = 6, $comment_lenth = 10, $before = '', $after = '
') {
global $wpdb, $tablecomments, $tableposts;
$comments = $wpdb->get_results("SELECT ID, comment_ID, comment_content, comment_author FROM $tableposts, $tablecomments WHERE $tableposts.ID=$tablecomments.comment_post_ID ORDER BY $tablecomments.comment_date DESC LIMIT $no_comments");
$output = '';
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_author_url = stripslashes($comment->comment_author_url);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$words=split(" ",$comment_content);
$comment_excerpt = join(" ",array_slice($words,0,$comment_lenth));
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$output .= $before . '' . $comment_author . ': ' . $comment_excerpt . '...
$output .= '" title="View the entire comment by ' . $comment_author . '">' . (read) . '' . $after;
}
echo $output;
You are using comment_author_url, but not selecting it from the the database in the query. Add it to the SELECT query and then it should work fine.
Ugh. And by adding it to the SELECT query, this is something I need to do within the database? I'm sorry, I feel so stupid. I'm just so new at SQL.
No, in the code for the function.
The line that starts $comments = $wpdb->get_results("SELECT ID
Just add a comma and the extra field that you want to pull. So it would now be SELECT ID, comment_ID, comment_content, comment_author, comment_author_url
Everyone is new at one point or another. :-)
Ah. Okay. Now I am starting to get the hang of some of this. Can anyone suggest any good reads that would help me learn more about PHP and how it works? I know the very basics, but would love to learn more.
And thanks MtDew! You have been a life-saver!
Man, you guys rock! The hack works purrfectly. I'm now using it on my site, along with the comment leaders hack. See it On my site. Woo-hoo!
Shaweeeet!
TG
~ Daisyhead
Here's a couple of sites that I think pretty helpful for learning PHP.
http://us2.php.net/tut.php
http://www.beginnersphp.co.uk/
http://www.developerfusion.com/php/
Hope this helps a little :)
I'm trying to "upgrade" this hack so that the comments on my password protected entries don't show up in my sidebar, but when I include the new text in my hacks file and upload it, I get a bunch of jibberish on my page. If I replace it with my old text, it works fine. Any idea what could be causing this??
how could i get smoething like this, but for posts?
Still having problems implementing this. When I do, I get the actual code executing on my page along with an error about an undefined error on line 5 of my include. Line five happens to be this line:
<?php get_recent_comments(); ?>
Help!
Daisyhead,
Sorry I didn't reply sooner (I was in San Diego for a week). What is the error that you are getting? Did you copy the code from the Wiki?
Anon,
There is a hack written for posts already.
http://wiki.wordpress.org/index.php/Recent%20Posts
This topic has been closed to new replies.