<?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>RLM &#187; custom loop</title>
	<atom:link href="http://www.rlmseo.com/blog/tag/custom-loop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rlmseo.com</link>
	<description></description>
	<lastBuildDate>Tue, 31 Jan 2012 03:37:47 +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 Pagination in Custom Loop</title>
		<link>http://www.rlmseo.com/blog/wordpress-pagination-in-custom-loop/</link>
		<comments>http://www.rlmseo.com/blog/wordpress-pagination-in-custom-loop/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 10:31:08 +0000</pubDate>
		<dc:creator>jcrens8392</dc:creator>
				<category><![CDATA[Loop Hacks]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[custom loop]]></category>
		<category><![CDATA[get_query_var]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[query vars]]></category>
		<category><![CDATA[query_posts]]></category>

		<guid isPermaLink="false">http://www.rlmseo.com/?p=571</guid>
		<description><![CDATA[If you use custom loops in WordPress you may run into pagination issues. Specifically, no matter what page you're on, only the first page's worth of posts are displayed. Here's a really quick solution to that problem using the query_posts() function.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.rlmseo.com/wp-content/uploads/2009/12/wordpress-pagination.jpg" rel="wp-prettyPhoto[571]"><img class="aligncenter size-full wp-image-1251" title="WordPress Pagination" src="http://www.rlmseo.com/wp-content/uploads/2009/12/wordpress-pagination.jpg" alt="WordPress Pagination" width="553" height="174" /></a></p>
<p>I wrote an article a while back about using a <a title="WordPress static homepage" href="http://www.rlmseo.com/blog/wordpress-static-homepage/">static homepage for your WordPress blog</a>. In that article I mentioned using a custom loop on this blog in the blog and tutorials sections. One problem you may run into when using a custom loop is that pagination doesn&#8217;t work like you&#8217;d expect it to.</p>
<p>In particular, you may notice that only the first page of posts are displayed no matter what page of posts you&#8217;re trying to view. I often use WordPress as a general purpose CMS in client projects and so I use a lot of custom loops and run into this issue a lot. Here&#8217;s the solution:</p>
<h2>Update query_posts with the proper query vars</h2>
<p>The solution to this problem is pretty simple. You need to tell WordPress to use the &#8220;paged&#8221; query variable in your custom loop, otherwise it&#8217;s ignored. If you&#8217;re using the <span class="code">query_posts</span> function for your custom loop, the easiest way to do this is like so:</p>
<pre>
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('paged=' . $paged . '&#038;cat=76'); // show posts in category 76 with pagination enabled
</pre>
<p>In this example, we first test to see if the &#8220;paged&#8221; query variable is set using the <span class="code">get_query_var</span> function, which will return false if it&#8217;s not set. If it is set, we&#8217;ll set <span class="code">$paged</span> equal to the value of that query variable and if not, we&#8217;ll set it equal to 1.</p>
<p>Then we initialize our custom loop using the <span class="code">query_posts</span> function by setting &#8220;paged&#8221; equal to our <span class="code">$paged</span> variable so that WordPress grabs the current page from the URL and displays the appropriate list of posts for that page.</p>
<p>I&#8217;m also looping through the posts in category #76 in this example, which is only there for illustrative purposes. That&#8217;s all there is to enabling pagination in custom WordPress loops.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rlmseo.com/blog/wordpress-pagination-in-custom-loop/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

