Featured: Pink for October

Sillyness, werd


Entry: Last (n) comments, for WP 1.2+


 

Meta & Errata


Here is the updated hack that lists the last (n) number of comments to your front page, version .03:

<?php
function last_comments() {
global $tableposts, $tablecomments;
$query = ("SELECT ID, post_title, comment_author, comment_date, comment_id
FROM $tableposts, $tablecomments WHERE
$tableposts.ID=$tablecomments.comment_post_ID ORDER BY
$tablecomments.comment_date DESC LIMIT 5");
while ($data = mysql_fetch_row($result)) {
echo stripslashes("$data[2]<br /><a href="".$blog_file."?p=$data[0]&c=1#comment-$data[4]">$data[1] ::<br /><br />\n");
} ?>

Insert that in your my-hacks.php file and place the function call <? last_comments() ?> in the page where you would like this to show up.

Changes since version .02 of the hack:

  • Cleaned up the syntax
  • Added the Comment ID to the URL string so you actually go to the comment that you were clicking on, and not just the top of the comment list.

If you would like to download this as a text file you can find it here (if you are using Safari, you won’t see the code, just save the file).  And remember this code is realeased under the same license that is in use on this site, so use it accordingly.

 

Comments & Pontifications


  1. personal avatar Onno
    Stroll on over and visit Onno
    March 1, 2007

    Hi Chris, I’ve tried to use this hack and I got some errors. If I edit an entry or post an new entry, I see this :”Warning: Cannot modify header information - headers already sent by (output started at /home/www/htdocs/url/blog/my-hacks.php:3) in /home/www/htdocs/url/blog/wp-admin/post.php on line 365”. Any hint?


  2. personal avatar Chris J. Davis
    Stroll on over and visit Chris J. Davis
    March 1, 2007

    My first thought would be to check and make sure that there aren’t any extra carriage returns at the end of the file, that usually is the culprit in these cases.

    Let me know if this works for you and I will see if I can dig up anything else.


  3. personal avatar Onno
    Stroll on over and visit Onno
    March 1, 2007

    Thank you for your answer! I forgot to say, that although I get this warning, changes in entries or even new entries are all the same visible in the blog. I hadn’t changed anything in the files before.


  4. personal avatar wife
    Stroll on over and visit wife
    March 1, 2007

    hey Chris - i found the output error with this script. you are mising another end bracket } right at the end. i got the same parse error as Onno and i got it to go away.


  5. personal avatar wife
    Stroll on over and visit wife
    March 1, 2007

    well, i get a different error this time:

    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/xxxxxx/public_html/yyyyyy/my-hacks.php on line 21

    i tried your plugin but it doesn’t seem to work for me. maybe i have the syntax wrong, too…


  6. personal avatar wife
    Stroll on over and visit wife
    March 1, 2007

    it worked! all i did is copy the code (from function on down to the last brackets) in your plugin version of this code, put it in the my-hacks.php and it worked! yay!


  7. personal avatar LG
    Stroll on over and visit LG
    March 1, 2007

    Fitght the spam! Use mysql query:

    $query = (“SELECT ID, post_title, comment_author, comment_date, comment_id FROM $tableposts, $tablecomments WHERE $tableposts.ID=$tablecomments.comment_post_ID AND $tablecomments.comment_approved=’1’ ORDER BY $tablecomments.comment_date DESC LIMIT 7”);

    instead of original! Everything is the same as in original only check for comment aproval is added…

Leave a Reply