Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Display 'last comment' in wordpress?

    Hello, I'm hoping someone can help me with this.

    On my main page of Wordpress I'm trying to make it so it displays the last posted comment under each article (single pages show all comments as usual, just talking about the main front page). An example would be here: http://destructoid.com/ where if you look underneath each article on the main page, it shows the last posted comment.


  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You would use get_comment() along with is_home(). Check out the WP Codex for more info
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    Exalted (03-03-2010)

  • #3
    New Coder
    Join Date
    Aug 2009
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hmm, it seems to be working but with one hiccup. It's displaying the "last post" made on the entire blog under each article. For example, my most recent article is about a video game, the last person to post says "Wow, that's cool!".. it shows "Wow, that's cool!" under all the other articles on the main page too, and not the last comment per each of those articles as I'm trying to do.

    I feel close... almost there

    Edit: Basically I'm just trying to use this to do it.. but I guess it needs some sort of conditional to only make it for the article that it's current in while on the main page.

    Code:
    <?php
    $comment_posts = get_option('woo_comment_posts');
    if (empty($comment_posts) || $comment_posts < 1) $comment_posts = 1;
    global $wpdb;
    $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
    comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved,
    comment_type,comment_author_url,
    SUBSTRING(comment_content,1,50) AS com_excerpt
    FROM $wpdb->comments
    LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
    $wpdb->posts.ID)
    WHERE comment_approved = '1' AND comment_type = '' AND
    post_password = ''
    ORDER BY comment_date_gmt DESC LIMIT ".$comment_posts;
    $comments = $wpdb->get_results($sql);
    $output = $pre_HTML;
    foreach ($comments as $comment) {
    ?>
    <li>
        <?php echo get_avatar( $comment, '35' ); ?>
    
    	<a href="<?php echo get_permalink($comment->ID); ?>#comment-<?php echo $comment->comment_ID; ?>" title="on <?php echo $comment->post_title; ?>">
    		<?php echo strip_tags($comment->comment_author); ?>: <?php echo strip_tags($comment->com_excerpt); ?>...
        </a>
        <div style="clear:both"></div>
    </li>
    <?php 
    }
    ?>
    Last edited by Exalted; 03-03-2010 at 06:40 PM.

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Can you post your code? it sounds like you're passing either no ID or the wrong/same one
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    New Coder
    Join Date
    Aug 2009
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JAY6390 View Post
    Can you post your code? it sounds like you're passing either no ID or the wrong/same one
    I edited and posted it above

  • #6
    New Coder
    Join Date
    Aug 2009
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I guess there is no way to make this work? Still trying lol


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •