<?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>PHP Starter &#187; Wordpress</title>
	<atom:link href="http://phpstarter.net/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpstarter.net</link>
	<description>PHP Tips &#38; Tools From Starters to Experts</description>
	<lastBuildDate>Fri, 25 Jun 2010 14:14:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Sort Posts by Comment Count in WordPress</title>
		<link>http://phpstarter.net/2009/01/sort-posts-by-comment-count-in-wordpress/</link>
		<comments>http://phpstarter.net/2009/01/sort-posts-by-comment-count-in-wordpress/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 12:00:10 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://phpstarter.net/?p=263</guid>
		<description><![CDATA[I use this technique to show the most popular posts on our homepage, and although this isn&#8217;t a core feature in WordPress, it&#8217;s not all that hard to do. All it takes is a little PHP and a single edit to one of your WordPress template files. I decided not to use a plugin because [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I use this technique to show the most popular posts on our homepage, and although this isn&#8217;t a core feature in WordPress, it&#8217;s not all that hard to do.  All it takes is a little PHP and a single edit to one of your WordPress template files.</p>
<p><span id="more-263"></span></p>
<p>I decided not to use a plugin because I find it easier to just edit the templates directly.  Here is the code:</p>
<pre class="brush: php">
&lt;?php
$results = $wpdb-&gt;get_results(&quot;SELECT ID, comment_count FROM wp_posts WHERE post_type = &#039;post&#039; &amp;&amp; post_status = &#039;publish&#039; ORDER BY comment_count DESC LIMIT 5&quot;);
foreach ($results as $r):
	query_posts(array(&#039;p&#039; =&gt; $r-&gt;ID));
	while (have_posts()):
		the_post();
?&gt;
&lt;!-- regular wordpress loop code goes here --&gt;
&lt;?php endwhile; endforeach; ?&gt;
</pre>
<p>This code manually calls a SQL query because there is no template tag that supports this method of sorting as of WordPress 2.7.  We are only querying for the post IDs because we will use that ID to call up the WordPress loop which will allow us to use the normal template tags inside the manual WordPress loop.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://phpstarter.net/2009/01/sort-posts-by-comment-count-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

