<?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>33dots &#187; query_posts</title>
	<atom:link href="http://www.33dots.com/index.php/tag/query_posts/feed" rel="self" type="application/rss+xml" />
	<link>http://www.33dots.com</link>
	<description></description>
	<lastBuildDate>Thu, 26 Aug 2010 09:29:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Excluding a category from the front page in Wordpress</title>
		<link>http://www.33dots.com/index.php/wordpress/excluding-a-category-from-the-front-page-in-wordpress.html</link>
		<comments>http://www.33dots.com/index.php/wordpress/excluding-a-category-from-the-front-page-in-wordpress.html#comments</comments>
		<pubDate>Thu, 06 Aug 2009 09:42:58 +0000</pubDate>
		<dc:creator>tony</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[query_posts]]></category>
		<category><![CDATA[wordpress category]]></category>

		<guid isPermaLink="false">http://www.33dots.com/?p=129</guid>
		<description><![CDATA[This is a very well known trick where we use the query_posts() template tag to control which posts to show up. The code has to be placed above the Loop in the index.php template file.
&#60;?php
if (is_home()) {
query_posts("cat=-3");
}
?&#62;
The code checks whether we are in home page and if it is, it excludes the category with id [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very well known trick where we use the <code>query_posts()</code> template tag to control which posts to show up. The code has to be placed above the <a title="Description of the Loop in wordpress site" href="http://codex.wordpress.org/The_Loop" target="_self"><em>Loop</em></a> in the <em>index.php</em> template file.</p>
<pre>&lt;?php
if (is_home()) {
query_posts("cat=-3");
}
?&gt;</pre>
<p>The code checks whether we are in home page and if it is, it excludes the category with id 3 from displaying in it. The <em>category id</em> can be found out from the wordpres&#8217;s <em>Edit Category</em> pages by mouse hovering the required category and its id will be shown in the browser&#8217;s status bar.<br />
More than one category could be excluded by using a code like this, <code>query_posts("cat=-2,-6,-8")</code></p>
<p>However, i recently noticed that it breaks the pagination, and so the <em>next</em> and <em>previous </em>page links at the bottom only shows the same home page. Pagination is the feature by which we split the home page into pages based on the max number of posts that can be displayed in the page.</p>
<p>The problem was because, the call to <code>query_posts()</code> causes the <code>wp_query</code> object to generate a new SQL query using our parameters and ignores the other parameters it receives via the URL (page number etc).</p>
<p>The proper way is to send the parameters in the URL together with our parameters and this can be done by including the variable <code>$query_string</code> in the call to <code>query_posts()</code>. When doing this way the quoted portion of the argument must begin with an ampersand (&amp;).<br />
The code now looks like this</p>
<pre>&lt;?php
if (is_home()) {
query_posts($query_string."&amp;cat=-3");
}
?&gt;</pre>
<p>Another technique is to use a code like this inside the Loop. <code><br />
&lt;?php if (in_category('3') &amp;&amp; is_home() ) continue; ?&gt;</code><br />
I&#8217;ve not tested this code myself, but looking at it i think it should work fine.</p>
<p>For a detailed information on what the <code>query_posts()</code> is capable of doing, visit this <a title="Wordpress codex page on query_posts()" href="http://codex.wordpress.org/Template_Tags/query_posts" target="_self">wordpress codex page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.33dots.com/index.php/wordpress/excluding-a-category-from-the-front-page-in-wordpress.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
