What's the code to access 'recent comments' in Wordpress?

Discussion in 'HTML & Website Design' started by Steupz, Apr 12, 2008.

  1. #1
    I don't wanna use the widget or install a separate plugin so I wanna paste it in my sidebar.php file; but I can't figure out what the code will be
     
    Steupz, Apr 12, 2008 IP
  2. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Errr...I might have gotten this wrong, but I'm pretty confident this will work.

    
    				<div class="blockinner">
    					<h1>Recent Comments</h1>
    					<?php $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 4"); ?>
    					<?php
    					if ( $comments ) : foreach ($comments as $comment) :
    						echo '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-'. $comment->comment_ID .'">'. get_comment_author() .'</a><br /><p>'. $comment->comment_content .'</p><div class="recentcommentsline"></div>';
    					endforeach; endif;?>
    				</div>
    
    Code (markup):
    Amend the h1 and div's as appropriate;)

    Cheers
     
    Spider-Man, Apr 12, 2008 IP
  3. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The PHP code looks correct, but I'd give the DIV an ID of "recent comments" and use a lower heading instead, but that's just me picking over semantics (it's what I do for a living).
     
    Dan Schulz, Apr 12, 2008 IP
  4. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Cheers for the tip Dan - I just ripped the code from a template I edited a bit last year...should still be good to go, though :)
     
    Spider-Man, Apr 12, 2008 IP
  5. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well it should be "recent-comments" not "recent comments" (I forgot to include the dash in there when I was writing the post).
     
    Dan Schulz, Apr 12, 2008 IP