WordPress – Create Your Own Popular Posts content in the sidebar

Highlighting the most popular posts on your site is a great way to send new visitors to your very best content and win them over.

There are a few different ways you can do this, and quite a few plugins out there to help. But why not base it on the number of comments? If you write a post that makes people talk, it must be a well written post (Most of the time…).

<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>

2 Replies to “WordPress – Create Your Own Popular Posts content in the sidebar”

  1. Pingback: WordPress – Create Your Own Popular Posts content in the sidebar

  2. Pingback: Tweets that mention Wordpress - Create Your Own Popular Posts content in the sidebar | WhileIf Blog -- Topsy.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*