<?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>scriptflipper.com &#187; pagination</title>
	<atom:link href="http://www.scriptflipper.com/tag/pagination/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptflipper.com</link>
	<description>online portfolio of Michael Ciccarelli</description>
	<lastBuildDate>Wed, 30 Jun 2010 22:14:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Fix pagination on query_posts()</title>
		<link>http://www.scriptflipper.com/2008/07/fix-pagination-on-query-posts/</link>
		<comments>http://www.scriptflipper.com/2008/07/fix-pagination-on-query-posts/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 21:51:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[query_posts]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://michaelciccarelli.com/?p=254</guid>
		<description><![CDATA[Here is a simple solution for those of you looking to customize your WordPress theme, to use the WordPress query_posts() function to retrieve your blog posts rather than the standard loop. I created a custom Page Template named &#8220;Blog&#8221; using query_posts() and assigned this template to be used on a designated Blog page within my [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple solution for those of you looking to customize your WordPress theme, to use the WordPress query_posts() function to retrieve your blog posts rather than the standard <a href="http://codex.wordpress.org/The_Loop">loop</a>.</p>
<p>I created a custom Page Template named &#8220;Blog&#8221; using query_posts() and assigned this template to be used on a designated Blog page within my site at http://michaelciccarelli.com/blog/ (a Blog within a Blog even). I did this mainly because my original homepage didn&#8217;t really resemble a traditional blog and I wanted something more than just your average archives page that only lists the titles of all your previous blog posts.</p>
<p><strong>So here&#8217;s my Blog Page Template&#8217;s Source Code:</strong><br />
<pre><code>
&lt;?php
/*
Template Name: Blog page
*/
?&gt;
&lt;?php get_header(); ?&gt;
&lt;div id=&quot;content&quot;&gt;
&nbsp;&nbsp;&lt;div id=&quot;primary&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php
&nbsp;&nbsp;&nbsp;&nbsp;$limit = get_option(&#039;posts_per_page&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;$paged = (get_query_var(&#039;paged&#039;)) ? get_query_var(&#039;paged&#039;) : 1;
&nbsp;&nbsp;&nbsp;&nbsp;query_posts(&#039;showposts=&#039; . $limit . &#039;&amp;paged=&#039; . $paged .&#039;&amp;cat=-166,-167,-168&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;$wp_query-&gt;is_archive = true; $wp_query-&gt;is_home = false;
&nbsp;&nbsp;&nbsp;&nbsp;?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;blog-post&quot; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;post-entry&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php the_content(__(&#039;Read the rest of this entry &amp;raquo;&#039;)); ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;&lt;!-- /post --&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php endwhile; ?&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- Page Navigation --&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php if (function_exists(&#039;wp_pagenavi&#039;)) : ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;pagenavi&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php wp_pagenavi(); ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php else : // Use WordPress default page navigation. ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;pages&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span class=&quot;older&quot;&gt;&lt;?php next_posts_link(&#039;&amp;laquo; Older Entries&#039;); ?&gt;&lt;/span&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span class=&quot;newer&quot;&gt;&lt;?php previous_posts_link(&#039;Newer Entries &amp;raquo;&#039;); ?&gt;&lt;/span&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php endif; ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php else : ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;blog-post&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2 class=&quot;post-title&quot;&gt;&lt;?php _e(&#039;404 - Not Found&#039;); ?&gt;&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;post-entry&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;&lt;?php _e(&#039;Sorry, no posts matched your criteria.&#039;); ?&gt;&lt;/p&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&lt;?php endif; ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php get_sidebar(); ?&gt;
&lt;/div&gt;&lt;!-- content --&gt;
&lt;span class=&quot;clr&quot;&gt;&lt;/span&gt;
&lt;?php get_footer(); ?&gt;
</code></pre></p>
<h3>Notes:</h3>
<p>The only bit you may want to alter in the function that retrieves your posts is the 3rd line in from top:<code>query_posts(&#039;showposts=&#039; . $limit . &#039;&amp;paged=&#039; . $paged .&#039;&amp;cat=-166,-167,-168&#039;);</code></p>
<p>Notice the <strong>&#038;cat=-166,-167,-168</strong> this basically says exclude the following category IDs, which in my case are portfolio categories, that I don&#8217;t want to display in my blog section. This parameter is more commonly used like <strong>cat=1,3,5</strong> which will only return posts from those categories.</p>
<p>$limit is assigned the &#8216;posts_per_page&#8217; option from your WordPress settings, this stopped working for me for some reason but not a big deal because it can be changed to something specific, like: <code>$limit = 20;</code></p>
<p><pre><code>
$wp_query-&gt;is_archive = true;
$wp_query-&gt;is_home = false;
</code></pre></p>
<p>These variables that come after the <code>query_posts()</code> are important as they force <code>posts_nav_link()</code> (and so pagination) to work, along with a few other helpful results gained for fooling WordPress into thinking we&#8217;re in the archive pages.</p>
<p><small>For the $paged stuff, see:</small> <a href="http://wordpress.org/support/topic/57912#post-312858 ">this support forum post</a> &#8211; <a href="http://wordpress.org/support/topic/152451?replies=12#post-679318">Source</a> [via <a href="http://wordpress.org/support/">WordPress Support</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptflipper.com/2008/07/fix-pagination-on-query-posts/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
	</channel>
</rss>
