Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter 512K

    (@512k)

    Works perfectly.
    512K

    Thread Starter 512K

    (@512k)

    OK, I found a better solution:

    <?php
    	$recent_comments = get_comments( array('post_id' => $newest_post_id,) );
    
    	foreach ($recent_comments as $comment)
    	{
    	?>
    	<?php
    	$comment_id = get_comment($comment->comment_ID);
    	$author = $comment_id->comment_author;
    	$commentdate = $comment_id->comment_date;
    	$content = $comment_id->comment_content;
    	?>
    	<p><?php echo $author; echo $commentdate;?></p>
    	<p><?php echo $content;?></p>
    	<?php
    	}
    ?>

    Thread Starter 512K

    (@512k)

    anyone?

    Thread Starter 512K

    (@512k)

    Thanks 123milliseconds, that’s exactly the code I searched for. But there is a little Problem. I changed the code to

    <?php
     	$pre_HTML ="";
     	$post_HTML ="";
      	global $wpdb;
    
     	$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $newest_post_id) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT $numberofcomments";
    
     	$comments = $wpdb->get_results($sql);
     	$output = $pre_HTML;
     	$output .= "\n<ul>";
      	foreach ($comments as $comment) {
     	$output .= "\n<li>".strip_tags($comment->comment_author) .":" . "<a href=\"" . get_permalink($comment->ID)."#comment-" . $comment->comment_ID . "\" title=\"on ".$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a></li>";
     	}
     	$output .= "\n</ul>";
      	$output .= $post_HTML;
      	echo $output;
    ?>

    Now I get the comments of the right post. But instead of listing me all the comments I want to have (e.g. 3 comments –> $numberofcomments = 3) it just displays the newest comment 3 times and not all of the three. I don’t know whats wrong.

Viewing 4 replies - 1 through 4 (of 4 total)