Wpcomment

Wpcomment

From ThaiiS Note (Wiki)

Jump to: navigation, search
<?php 
 
$comments = get_comments('post_id=172&number=5&comment_approved=1');
 foreach($comments as $comm) :
	echo("<li id=\"commentbox\"><small class=\"commentmetadata\">Requested by : <b>");
	echo($comm->comment_author);
	echo(" </b>: ");
	echo($comm->comment_date);
		echo("</small><br /> <b><p>");
	echo($comm->comment_content);  
	echo("</p></b></li>");
endforeach;
?>

a

 <?php 
$comments = get_comments('post_id=172&number=5&comment_approved=1');
  foreach($comments as $comm) :
  echo userphoto_comment_author_thumbnail();
	echo("Requested by :");
	echo($comm->comment_author);
	echo(" : ");
	echo($comm->comment_date);
	echo("<br /> <b>");
	echo($comm->comment_content);
	echo("</b><hr>");
  endforeach;
?>
	 
<?php 
$comments = get_comments('pagename=songrequest&number=5');
  foreach($comments as $comm) :
    echo($comm->comment_author);
  endforeach;
?>

Recent Comments

<?php
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 =
$wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT 10";
$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;?>

show Ads on Wordpress Homepage Only

<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
YOUR ADVERTISEMENT CODE HERE
<?php } ?>

Display The Most Commented Posts

<h2>Popular Posts</h2>
<ul>
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>

<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>

</ul>

Most commented posts from 2008

<ul>
<?php
$result = $wpdb->get_results("SELECT comment_count,ID,post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN '2008-01-01' AND '2008-12-31' ORDER BY comment_count DESC LIMIT 0 , 10");

foreach ($result as $topten) {
    $postid = $topten->ID;
    $title = $topten->post_title;
    $commentcount = $topten->comment_count;
    if ($commentcount != 0) {
    ?>
         <li><a href="<?php echo get_permalink($postid); ?>"><?php echo $title ?></a></li>

    <?php }
}
?>
</ul>