对于大多数发表评论的帖子,您可以在侧栏中使用自定义循环,例如:
<h3>Most Commented Posts</h3>
<?php $most_commented = new WP_Query(\'orderby=comment_count&posts_per_page=5\');
if($most_commented->have_posts()) : ?>
<ul class="most-commented-posts">
<?php while($most_commented->have_posts()) : $most_commented->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?> (<?php comments_number(\'0\',\'1\',\'%\'); ?>)</a></li>
<?php endwhile; ?>
</ul><!-- most-commented-posts -->
<?php endif; wp_reset_query(); ?>
对于顶级评论者,您可以使用以下内容:
Top Commenters: exclude admin
对于总评论等评论统计信息,请使用此功能:
function comment_stats() {
global $wpdb;
// approved responses (comments and trackbacks)
$comment_stats[\'total_responses\'] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = \'1\'");
// trackback count
$comment_stats[\'total_trackbacks\'] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = \'pingback\' OR comment_type = \'trackback\'");
// comments count
$comment_stats[\'total_comments\'] = $comment_stats[\'total_responses\'] - $comment_stats[\'total_trackbacks\'];
// Akismet spam captured
if(function_exists(\'akismet_count\')) {
$comment_stats[\'spam_blocked\'] = akismet_count();
}
if(!empty($comment_stats)) {
$html .= "<ul class=\\"comments-stats\\">\\n";
foreach($comment_stats as $stat => $stat_value) :
if(isset($stat_value) && $stat_value > 0) {
$stat_name = str_replace("_", " ", $stat);
$html .= "<li>" .ucwords($stat_name). " : " .number_format($stat_value). "</li>\\n";
}
endforeach;
$html .= "</ul>\\n";
echo $html;
}
}