Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Display Most Popular Posts without a Plugin

Simple but effective method of displaying your blog’s most popular posts based on comment count. This code snippet may be placed anywhere within your theme’s files (i.e., no loop required). Check it out:

<h3>Popular Posts</h3>
<?php $result = $wpdb->get_results("
	SELECT comment_count, ID, post_title 
	FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 7

foreach ($result as $post) {
	$postid = $post->ID;
	$title = $post->post_title;
	$commentcount = $post->comment_count;
	if ($commentcount != 0) { ?>

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

	<?php } ?>
<?php } ?>

Once in place, this code will display the seven most popular posts along with their associated comment count in unordered list format. Customize according to your needs.

Source: ProBlogDesign (404 link removed 2013/09/15)