<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zack LivePopular Posts | Best Premium WordPress Themes - Zack Live</title>
	<atom:link href="http://zacklive.com/tag/popular/feed/" rel="self" type="application/rss+xml" />
	<link>http://zacklive.com</link>
	<description>Free Online Resource</description>
	<lastBuildDate>Wed, 02 May 2012 14:42:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>WordPress: Getting Most Popular(Commented) Posts</title>
		<link>http://zacklive.com/wordpress-getting-most-popularcommented-posts/589/</link>
		<comments>http://zacklive.com/wordpress-getting-most-popularcommented-posts/589/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 00:04:31 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Comments]]></category>
		<category><![CDATA[Popular Posts]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://zacklive.com/?p=589</guid>
		<description><![CDATA[After my post Getting Recent Posts In WordPress before, I am thinking about getting the most popular posts or most commented posts. Talking about most popular posts, are those most posts  commented mean they are most popular. Not really, there may be some posts, they&#8217;ve been read many times, but people seldom leave comments, aren&#8217;t they popular? [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://zacklive.com/wp-content/uploads/2009/11/halo_wordpress-400x310.jpg"><img class="aligncenter size-full wp-image-591" title="halo_wordpress-400x310" src="http://zacklive.com/wp-content/uploads/2009/11/halo_wordpress-400x310.jpg" alt="halo_wordpress-400x310" width="400" height="310" /></a></p>
<p>After my post <a title="Getting Recent Posts in WordPress" rel="bookmark" href="http://zacklive.com/getting-recent-posts-in-wordpress/573/">Getting Recent Posts In WordPress</a> before, I am thinking about getting the most popular posts or most commented posts. Talking about most popular posts, are those most posts  commented mean they are most popular. Not really, there may be some posts, they&#8217;ve been read many times, but people seldom leave comments, aren&#8217;t they popular? So at the first place, I thought popular posts should be calculated by both view count and comment count. But when I go deep to coding, I found that it&#8217;s much more difficult to get the view count than comment count, because WordPress saves comment count by default, we can get the number from the database. On the other hand, view count is not saved. Which means we need to count every posts from the every beginning by ourselves, and most of time, this is not worth to do. This reminds me the <a title="wordpress plugin popularity contest" href="http://wordpress.org/extend/plugins/popularity-contest/">Popularity Contest</a> plugin, it counts the views, comments, trackbacks and so on, to determine the popularity of posts. If you want a exactly perfect popular posts list, you may try out this plugin. But I prefer a light way to do it as it&#8217;s not a really important need, let focus on most commented posts.</p>
<p>The first solution I found is from <a title="wordpress most popular posts" href="http://bavotasan.com/tutorials/how-to-list-your-most-popular-posts-in-wordpress/">bavotasan.com</a>, it&#8217;s simple and clear. Here is the main code:</p>
<pre class="brush: php; title: ; notranslate">
function popularPosts($num) {
    global $wpdb;

    $posts = $wpdb-&gt;get_results(&quot;SELECT comment_count, ID, post_title FROM $wpdb-&gt;posts ORDER BY comment_count DESC LIMIT 0 , $num&quot;);

    foreach ($posts as $post) {
        setup_postdata($post);
        $id = $post-&gt;ID;
        $title = $post-&gt;post_title;
        $count = $post-&gt;comment_count;

        if ($count != 0) {
            $popular .= '&lt;li&gt;';
            $popular .= '&lt;a href=&quot;' . get_permalink($id) . '&quot; title=&quot;' . $title . '&quot;&gt;' . $title . '&lt;/a&gt; ';
            $popular .= '&lt;/li&gt;';
        }
    }
    return $popular;
}
</pre>
<p>But when I came to <a title="wordpress most popular posts" href="http://www.blogohblog.com/10-wordpress-hacks-to-make-your-life-easy/">blogohblog.com</a>, the blogger used a more complex way to do it, he thought about more details, like do not count unaproved comments, able to set duration and should the password protected posted be counted or not. To make this happen, he re-counted comments by the comment_post_ID, very clever, here is the codes:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php function most_popular_posts($no_posts = 5, $before = '&lt;li&gt;', $after = '&lt;/li&gt;', $show_pass_post = false, $duration='') {
    global $wpdb;
    $request = &quot;SELECT ID, post_title, COUNT($wpdb-&gt;comments.comment_post_ID) AS 'comment_count' FROM $wpdb-&gt;posts, $wpdb-&gt;comments&quot;;
    $request .= &quot; WHERE comment_approved = '1' AND $wpdb-&gt;posts.ID=$wpdb-&gt;comments.comment_post_ID AND post_status = 'publish'&quot;;
    if(!$show_pass_post) $request .= &quot; AND post_password =''&quot;;
    if($duration !=&quot;&quot;) { $request .= &quot; AND DATE_SUB(CURDATE(),INTERVAL &quot;.$duration.&quot; DAY) &lt; post_date &quot;;
}
    $request .= &quot; GROUP BY $wpdb-&gt;comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts&quot;;
    $posts = $wpdb-&gt;get_results($request);
    $output = '';
    if ($posts) {
        foreach ($posts as $post) {
            $post_title = stripslashes($post-&gt;post_title);
            $comment_count = $post-&gt;comment_count;
            $permalink = get_permalink($post-&gt;ID);
            $output .= $before . '&lt;a href=&quot;' . $permalink . '&quot; title=&quot;' . $post_title.'&quot;&gt;' . $post_title . '&lt;/a&gt; (' . $comment_count.')' . $after;
       }
    } else {
        $output .= $before . &quot;None found&quot; . $after;
    }
    echo $output;
} ?&gt;
</pre>
<p>The second one is a better choice, more options and flexibility. You can display popular posts list by placing the following code to your theme, sidebar.php or index.php or else.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php most_popular_posts(); ?&gt;
</pre>
<p>The original codes from blogohblog works fine, but WordPress requires to use $wpdb-&gt;prepare for DB queries, if you want to upload your theme to WordPress theme directory, you need to do some modification, here is my version which works fine with my theme, and accepted by WordPress theme directory.</p>
<pre class="brush: php; title: ; notranslate">
function most_popular_posts($no_posts = 5, $before = '&lt;li&gt;', $after = '&lt;/li&gt;', $show_pass_post = false)
	{
		global $wpdb;
		$posts = $wpdb-&gt;get_results(
			$wpdb-&gt;prepare(&quot;
		SELECT ID, post_title, COUNT($wpdb-&gt;comments.comment_post_ID) AS 'comment_count'
		FROM $wpdb-&gt;posts, $wpdb-&gt;comments
		WHERE comment_approved = %s AND $wpdb-&gt;posts.ID=$wpdb-&gt;comments.comment_post_ID AND post_status = %s AND post_password = %s
		GROUP BY $wpdb-&gt;comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts&quot;,
		'1','publish','')
		);
		$output = '';
		if ($posts) {
		foreach ($posts as $post) {
		$post_title = stripslashes($post-&gt;post_title);
		$comment_count = $post-&gt;comment_count;
		$permalink = get_permalink($post-&gt;ID);
		$output .= $before . '&lt;a href=&quot;' . $permalink . '&quot; title=&quot;' . $post_title.'&quot;&gt;' . $post_title . '&lt;/a&gt; (' . $comment_count.')' . $after;
		}
		} else {
		$output .= $before . &quot;None found&quot; . $after;
		}
		echo $output;
	}
</pre>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://zacklive.com/separate-trackbacks-from-comments-in-wordpress-2-7/1022/" title="Separate Trackbacks from Comments in WordPress 2.9">Separate Trackbacks from Comments in WordPress 2.9</a></li><li><a href="http://zacklive.com/choose-a-syntax-highlighter-plugin-for-wordpress/926/" title="Choose a Syntax Highlighter Plugin for WordPress">Choose a Syntax Highlighter Plugin for WordPress</a></li><li><a href="http://zacklive.com/wordpress-month-special-offer-from-packtpub/3204/" title="WordPress Month Special Offer from PacktPub">WordPress Month Special Offer from PacktPub</a></li><li><a href="http://zacklive.com/free-wordpress-theme-brominerary-theme/3094/" title="Free WordPress Theme: Brominerary Theme">Free WordPress Theme: Brominerary Theme</a></li><li><a href="http://zacklive.com/free-wordpress-theme-fresh-theme/3060/" title="Free WordPress Theme: Fresh Theme">Free WordPress Theme: Fresh Theme</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://zacklive.com/wordpress-getting-most-popularcommented-posts/589/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Organize Popular Posts of Your Blog</title>
		<link>http://zacklive.com/how-to-organize-popular-posts-of-your-blog/236/</link>
		<comments>http://zacklive.com/how-to-organize-popular-posts-of-your-blog/236/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 19:17:32 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Blog and WordPress]]></category>
		<category><![CDATA[Category]]></category>
		<category><![CDATA[Popular Posts]]></category>

		<guid isPermaLink="false">http://zacklive.com/?p=236</guid>
		<description><![CDATA[Popular posts are important assests of your blog. They attract most of your readers. To organize popular posts can help readers find out more great posts and  go deeper into your blog. I am going to introduce the easiest way to organize popular posts by using catogory. It&#8217;s as easy as abc, all you have [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://zacklive.com/wp-content/uploads/2008/09/halo_wordpress.jpg"><img class="size-medium wp-image-240 aligncenter" title="WordPress Popular Posts" src="http://zacklive.com/wp-content/uploads/2008/09/halo_wordpress-400x310.jpg" alt="" width="400" height="310" /></a></p>
<p>Popular posts are important assests of your blog. They attract most of your readers. To organize popular posts can help readers find out more great posts and  go deeper into your blog. I am going to introduce the easiest way to organize popular posts by using catogory.</p>
<p>It&#8217;s as easy as abc, all you have to do is to create a category called &#8220;Popular Posts&#8221;, remember to set the category slug to &#8220;popular&#8221;, so that you can find all your popular posts under the URL of blogdomain.com/popular. The second step is to determine which posts should be included in the Popular category. As the owner of your blog, you may got some idea about which posts are well liked by your readers. And you can also put some important posts which highly recommendable to your readers into the Popular category. If you have some else for popular posts, but you are not sure which posts to be put into the category, you can check out your Google Analytics, and go to the Content Overview section, you can see which posts got most traffic. That&#8217;s your most popular posts, you can choose some of them to put into the Popular category.</p>
<p>As the result, when a reader come to your blog, he/she may be attracted by the &#8220;Popular Posts&#8221; category, and can find out all the popular posts by one click.</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://zacklive.com/wordpress-getting-most-popularcommented-posts/589/" title="WordPress: Getting Most Popular(Commented) Posts">WordPress: Getting Most Popular(Commented) Posts</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://zacklive.com/how-to-organize-popular-posts-of-your-blog/236/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

