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>
&lt;?<a title="See also WordPress - Batch Delete Post Revisions" href="http://www.whileifblog.com/2010/09/22/wordpress-batch-delete-post-revisions/">php</a> $result = $wpdb-&gt;get_results(&quot;SELECT comment_count,ID,post_title
FROM $wpdb-&gt;posts ORDER BY comment_count DESC LIMIT 0 , 5&quot;);
foreach ($result as $post) {
setup_postdata($post);
$postid = $post-&gt;ID;
$title = $post-&gt;post_title;
$commentcount = $post-&gt;comment_count;
if ($commentcount != 0) { ?&gt;
&lt;li&gt;&lt;a href=&quot;&lt;?<a title="See also WordPress - How to Display any External RSS Feed on Your Site" href="http://www.whileifblog.com/2010/12/30/wordpress-how-to-display-any-external-rss-feed-on-your-site/">php</a> echo get_permalink($postid); ?&gt;&quot; title=&quot;&lt;?<a title="See also WordPress - Display post thumbnail in your RSS feed" href="http://www.whileifblog.com/2010/12/27/wordpress-display-post-thumbnail-in-your-rss-feed-2/">php</a> echo
$title ?&gt;&quot;&gt;
&lt;?<a title="See also WordPress - Dynamic Copyright Date in Footer" href="http://www.whileifblog.com/2012/03/11/wordpress-dynamic-copyright-date-in-footer/">php</a> echo $title ?&gt;&lt;/a&gt; {&lt;?<a title="See also WordPress - Programmatically Creating Posts" href="http://www.whileifblog.com/2010/09/20/wordpress-programmatically-creating-posts/">php</a> echo $commentcount ?&gt;}&lt;/li&gt;
&lt;?<a title="See also WordPress - Read More link jumps to top of post page" href="http://www.whileifblog.com/2010/12/29/wordpress-read-more-link-jumps-to-top-of-post-page/">php</a> } } ?&gt;
&lt;/ul&gt;

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

More in Code, PHP, Software, Wordpress (107 of 178 articles)


Have you seen other bloggers who display their other blog’s feed on their site. You want to do it too ...