<?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>WP Engineer &#187; get_posts</title>
	<atom:link href="http://wpengineer.com/tag/get_posts/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Sun, 22 Jan 2012 13:32:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Correct Pagination with get_posts</title>
		<link>http://wpengineer.com/1263/correct-pagination-with-get_posts/</link>
		<comments>http://wpengineer.com/1263/correct-pagination-with-get_posts/#comments</comments>
		<pubDate>Thu, 28 May 2009 22:36:29 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[get_posts]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1263</guid>
		<description><![CDATA[If you like to show your posts a little bit different on your homepage or category page. For example having a different amount of posts showing on these pages, as it is set in your admin, you will get a problem with the pagination function. Because WordPress and several paging Plugins use $wp_query->max_num_pages. max_num_pages is [...]]]></description>
			<content:encoded><![CDATA[<p>If you like to show your posts a little bit different on your homepage or category page. For example having a different amount of posts showing on these pages, as it is set in your admin, you will get a problem with the pagination function. Because WordPress and several paging Plugins use <strong>$wp_query->max_num_pages</strong>.<br />
<span id="more-1263"></span><br />
<code>max_num_pages</code> is the result of available posts divided by the set number of posts per page. For example we set 10 posts per page, but we have on our starting page 14 posts, it will mess up the pagination.</p>
<p>My solution works with the WordPress pagination and looks like this:</p>
<pre lang="php">
//detect the set number of posts per page
$ppp = get_option(&#039;posts_per_page&#039;);

// first page 14 posts
if (!is_paged()) {
    $posts = get_posts(&#039;numberposts=14&#039;);
// second page with offset
} elseif($paged == 2) {
    $posts = get_posts(&#039;offset=14&#039;);
// all other pages with settings from backend
} else {
    $offset = $ppp*($paged-2)+14;
    $posts = get_posts(&#039;offset=&#039;.$offset);
}

if($posts) :
    foreach ($posts as $post) :
        //your code
    endforeach;
endif;
</pre>
<p>This might be not the most intelligent solution, but it works. If anybody has a better idea, please let us know in the comments.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1263/correct-pagination-with-get_posts/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

