WordPress.org

Ready to get started?Download WordPress

Forums

Recent comments w/ portion of comment (52 posts)

  1. enils
    Member
    Posted 10 years ago #

    yeah it works! with some match things of course ^_^

  2. Lester Chan
    Member
    Posted 10 years ago #

    nice!

  3. Anonymous
    Unregistered
    Posted 10 years ago #

    Nice ! I added the author and post title myself.

  4. Nick Momrik
    Member
    Posted 10 years ago #

  5. Daisyhead
    Member
    Posted 10 years ago #

    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

  6. Nick Momrik
    Member
    Posted 10 years ago #

    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.

  7. Daisyhead
    Member
    Posted 10 years ago #

    Thanks! I'm still having problems with tweaking it, but I'm going to try tomorrow when I'm not so freaking tired.
    -Daisyhead

  8. southerngal
    Member
    Posted 10 years ago #

    Will this skip over the comments in a private, protected post?

  9. Nick Momrik
    Member
    Posted 10 years ago #

    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.

  10. Nick Momrik
    Member
    Posted 10 years ago #

    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).

  11. Anonymous
    Unregistered
    Posted 10 years ago #

    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

  12. Anonymous
    Unregistered
    Posted 10 years ago #

    I think I just figured it out! Yay!! =)

  13. Nick Momrik
    Member
    Posted 10 years ago #

    Remove those two lines I mentioned above and replace with these...
    $output .= $before . '' . $comment_author . ': ' . $comment_excerpt . '…
    $output .= $permalink . '" title="View the entire comment by ' . $comment_author.'">(go)
    ' . $after;
    I think that's what you are looking for.

  14. Nick Momrik
    Member
    Posted 10 years ago #

    Looks like you beat me to it!! :-P

  15. Edlef
    Member
    Posted 10 years ago #

    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!

  16. Nick Momrik
    Member
    Posted 10 years ago #

    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.

  17. Nick Momrik
    Member
    Posted 10 years ago #

    It's printing "$comment..." because you have it inside the single quotes. It has to be moved outside of the quotations.

  18. Daisyhead
    Member
    Posted 10 years ago #

    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

  19. Nick Momrik
    Member
    Posted 10 years ago #

    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.

  20. Daisyhead
    Member
    Posted 10 years ago #

    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;

  21. Nick Momrik
    Member
    Posted 10 years ago #

    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.

  22. Daisyhead
    Member
    Posted 10 years ago #

    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.

  23. Nick Momrik
    Member
    Posted 10 years ago #

    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. :-)

  24. Daisyhead
    Member
    Posted 10 years ago #

    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!

  25. TechGnome
    Moderator
    Posted 10 years ago #

    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

  26. Hamoudy
    Member
    Posted 10 years ago #

    ~ 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 :)

  27. Daisyhead
    Member
    Posted 10 years ago #

    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??

  28. Anonymous
    Unregistered
    Posted 10 years ago #

    how could i get smoething like this, but for posts?

  29. Daisyhead
    Member
    Posted 10 years ago #

    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!

  30. Nick Momrik
    Member
    Posted 10 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.