Support » Plugins and Hacks » Recent comments w/ portion of comment

Viewing 15 replies - 16 through 30 (of 52 total)
  • 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

Viewing 15 replies - 16 through 30 (of 52 total)
  • You must be logged in to reply to this topic.