<?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>PSD to Wordpress &#187; query_posts</title> <atom:link href="http://www.sramekdesign.com/tag/query_posts/feed/" rel="self" type="application/rss+xml" /><link>http://www.sramekdesign.com</link> <description>Get your PSD sliced into the XHTML valid Wordpress theme. SramekDesign offers cheap and fast PSD to Wordpress conversion service.</description> <lastBuildDate>Wed, 20 Apr 2011 04:33:37 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>WordPress: display posts from certain category</title><link>http://www.sramekdesign.com/wordpress/wordpress-display-posts-from-certain-category/</link> <comments>http://www.sramekdesign.com/wordpress/wordpress-display-posts-from-certain-category/#comments</comments> <pubDate>Sun, 08 Mar 2009 09:46:06 +0000</pubDate> <dc:creator>Tomas Sramek</dc:creator> <category><![CDATA[Wordpress]]></category> <category><![CDATA[category]]></category> <category><![CDATA[loop]]></category> <category><![CDATA[query_posts]]></category> <category><![CDATA[show]]></category> <category><![CDATA[showposts]]></category> <category><![CDATA[WP_Query]]></category><guid
isPermaLink="false">http://www.sramekdesign.com/?p=185</guid> <description><![CDATA[Recently my client&#8217;s design required displaying posts in sidebar only from one category. To solve this problem I decided to use class WP_Query. The first we have to create instance of WP_Query: Then call method query(); to start the query. This is actually same as you would be using query_posts(); Parameter cat indicates which category&#8217;s [...]]]></description> <content:encoded><![CDATA[<p>Recently my client&#8217;s design required displaying posts in sidebar only from one category. To solve this problem I decided to use class WP_Query.</p><p>The first we have to create instance of WP_Query:</p><pre lang="php"><?php $recent = new WP_Query(); ?></pre><p>Then call method query(); to start the query. This is actually same as you would be using query_posts();<br
/> Parameter <strong>cat</strong> indicates which category&#8217;s posts are shown. Parameter <strong>showposts</strong> is the number of posts to be displayed.</p><pre lang="php"><?php $recent->query('cat=1&#038;showposts=5'); ?></pre><p>Now we can use loop:</p><pre class="brush: php; title: ; notranslate">
&lt;?php while($recent-&gt;have_posts()) : $recent-&gt;the_post(); ?&gt;
&lt;!-- Here goes some code --&gt;
&lt;?php endwhile; ?&gt;
</pre><p>Final code that displays last 5 posts&#8217; permalinks from category with ID=1 looks like this:</p><pre class="brush: php; title: ; notranslate">
&lt;h2&gt;Last posts&lt;/h2&gt;
&lt;?php $recent = new WP_Query(); ?&gt;
&lt;?php $recent-&gt;query('cat=1&amp;showposts=5'); ?&gt;
&lt;?php while($recent-&gt;have_posts()) : $recent-&gt;the_post(); ?&gt;
&lt;ul&gt;
	&lt;li&gt;
            &lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;
            &lt;?php the_title(); ?&gt;
            &lt;/a&gt;
       &lt;/li&gt;
&lt;/ul&gt;
&lt;?php endwhile; ?&gt;
</pre><p>Using your own WP_Query instance and loop prevents you from problems that might cause plugins&#8217; loops and use of conditional tags.</p><div
id="crp_related"><h3>Related Posts:</h3><ul><li><a
href="http://www.sramekdesign.com/wordpress/display-recent-and-related-posts-without-duplicating-each-other/" rel="bookmark" class="crp_title">Display recent and related posts without duplicating each other</a><span
class="crp_excerpt"> My client asked me to implement lists of recent and ...</span></li><li><a
href="http://www.sramekdesign.com/wordpress/display-recent-comments-with-avatar/" rel="bookmark" class="crp_title">Display recent comments with avatar</a><span
class="crp_excerpt"> From time to time clients ask me implement recent posts. ...</span></li><li><a
href="http://www.sramekdesign.com/wordpress/how-to-display-external-rss-feed/" rel="bookmark" class="crp_title">How to display external RSS feed</a><span
class="crp_excerpt"> Don't mess with RSS plugins! Here is a snippet that ...</span></li><li><a
href="http://www.sramekdesign.com/wordpress/display-last-posts/" rel="bookmark" class="crp_title">Display last posts</a><span
class="crp_excerpt"> If you want to display five last posts from your ...</span></li></ul></div>]]></content:encoded> <wfw:commentRss>http://www.sramekdesign.com/wordpress/wordpress-display-posts-from-certain-category/feed/</wfw:commentRss> <slash:comments>31</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching 2/22 queries in 0.025 seconds using disk: basic
Object Caching 329/369 objects using disk: basic
Content Delivery Network via N/A

Served from: www.sramekdesign.com @ 2012-02-04 03:35:23 -->
