<?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; Pagination</title>
	<atom:link href="http://wpengineer.com/tag/pagination/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Mon, 21 May 2012 22:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress Pagination Again</title>
		<link>http://wpengineer.com/2133/wordpress-pagination-again/</link>
		<comments>http://wpengineer.com/2133/wordpress-pagination-again/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 09:40:01 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2133</guid>
		<description><![CDATA[Some days ago, Frank wrote a post about Custom Pagination without WordPress Plugins. Jay comment, that something like this already exists (since Version 2.1). We don't know everything. How do you get it in your template? The best is, if you have a function, which you can use in several templates. function my_paginate_links() { global [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-14.jpg" alt="" title="WordPress-Christmas-2010-14" width="400" height="267" class="alignnone size-full wp-image-2135" /><br />
Some days ago, Frank wrote a post about <a title="Custom Pagination without Plugins" href="http://wpengineer.com/2078/custom-pagination-without-wordpress-plugins/">Custom Pagination without WordPress Plugins</a>. <a title="Jays Kommentar" href="http://wpengineer.com/2078/custom-pagination-without-wordpress-plugins/#comment-5488">Jay</a> comment, that something like this <a title="WordPress Codex" href="http://codex.wordpress.org/Function_Reference/paginate_links">already exists</a> (since Version 2.1). We don't know everything. <img src='http://wpengineer.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
<span id="more-2133"></span><br />
How do you get it in your template? The best is, if you have a function, which you can use in several templates.</p>
<pre lang="php">
function my_paginate_links() {
    global $wp_rewrite, $wp_query;
    $wp_query-&gt;query_vars&#091;&#039;paged&#039;&#093; &gt; 1 ? $current = $wp_query-&gt;query_vars&#091;&#039;paged&#039;&#093; : $current = 1;

    $pagination = array(
        &#039;base&#039; =&gt; @add_query_arg(&#039;page&#039;,&#039;%#%&#039;),
        &#039;format&#039; =&gt; &#039;&#039;,
        &#039;total&#039; =&gt; $wp_query-&gt;max_num_pages,
        &#039;current&#039; =&gt; $current,
        &#039;prev_text&#039; =&gt; __(&#039;« Previous&#039;),
        &#039;next_text&#039; =&gt; __(&#039;Next »&#039;),
        &#039;end_size&#039; =&gt; 1,
        &#039;mid_size&#039; =&gt; 2,
        &#039;show_all&#039; =&gt; true,
        &#039;type&#039; =&gt; &#039;list&#039;
    );

    if ( $wp_rewrite-&gt;using_permalinks() )
            $pagination&#091;&#039;base&#039;&#093; = user_trailingslashit( trailingslashit( remove_query_arg( &#039;s&#039;, get_pagenum_link( 1 ) ) ) . &#039;page/%#%/&#039;, &#039;paged&#039; );

    if ( !empty( $wp_query-&gt;query_vars&#091;&#039;s&#039;&#093; ) )
            $pagination&#091;&#039;add_args&#039;&#093; = array( &#039;s&#039; =&gt; get_query_var( &#039;s&#039; ) );

    echo paginate_links( $pagination );
}
</pre>
<p>In your template only my_paginate_links() will be called. And this is how the output looks like, of course you can adjust it to your liking:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/wordpress-pagination.jpg" alt="WordPress Pagination" title="WordPress Pagination" width="150" height="150" class="alignnone size-full wp-image-2134" /></p>
<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/2133/wordpress-pagination-again/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Custom Pagination without WordPress Plugins</title>
		<link>http://wpengineer.com/2078/custom-pagination-without-wordpress-plugins/</link>
		<comments>http://wpengineer.com/2078/custom-pagination-without-wordpress-plugins/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 10:41:09 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[advent]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2078</guid>
		<description><![CDATA[On day 9 of our Advents Calendar we show a custom pagination function which allows a user to insert custom next, previous or numbered page links into a post. Use the follow code for an custom plugin or insert the function in your theme, inside the functions.php. Please see the second code-area for an example [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-09-300x200.jpg" alt="" title="WordPress-Christmas-2010-09" width="300" height="200" class="aligncenter size-medium wp-image-2100" /><br />
On day 9 of our Advents Calendar we show a custom pagination function which allows a user to insert custom next, previous or numbered page links into a post. Use the follow code for an custom plugin or insert the function in your theme, inside the functions.php. Please see the second code-area for an example to hook inside the function for custom parameters.<br />
<span id="more-2078"></span></p>
<h4>Example Screenshots</h4>
<p><img src="http://wpengineer.com/wp-content/uploads/wp-pagination2.png" alt="" title="wp-pagination2" width="138" height="41" class="size-full wp-image-2080" /> <img src="http://wpengineer.com/wp-content/uploads/wp-pagination.png" alt="" title="wp-pagination" width="145" height="74" class="size-full wp-image-2079" /></p>
<h4>The function</h4>
<p>Now the function for the pagination</p>
<pre>
function fb_paging_bar( $args = array() ) {

	$defaults = array(
		&#039;range&#039;           =&gt; 4,
		&#039;custom_query&#039;    =&gt; FALSE,
		&#039;previous_string&#039; =&gt; __( &#039;&laquo;&laquo;&laquo;&#039;, FB_GREYFOTO_TEXTDOMAIN ),
		&#039;next_string&#039;     =&gt; __( &#039;&raquo;&raquo;&raquo;&#039;, FB_GREYFOTO_TEXTDOMAIN ),
		&#039;view_fp&#039;         =&gt; TRUE,
		&#039;view_lp&#039;         =&gt; TRUE,
		&#039;before_output&#039;   =&gt; &#039;&lt;div class=&quot;postlink&quot;&gt;&#039;,
		&#039;after_output&#039;    =&gt; &#039;&lt;/div&gt;&#039;
	);

	$args = wp_parse_args(
		$args,
		apply_filters( &#039;fb_paging_bar_defaults&#039;, $defaults )
	);

	$args&#091;&#039;range&#039;&#093; = (int) $args&#091;&#039;range&#039;&#093; - 1;
	if ( !$args&#091;&#039;custom_query&#039;&#093; )
		$args&#091;&#039;custom_query&#039;&#093; = @$GLOBALS&#091;&#039;wp_query&#039;&#093;;
	$count = (int) $args&#091;&#039;custom_query&#039;&#093;-&gt;max_num_pages;
	$page  = intval( get_query_var( &#039;paged&#039; ) );
	$ceil  = ceil( $args&#091;&#039;range&#039;&#093; / 2 );

	if ( $count &lt;= 1 )
		return FALSE;

	if ( !$page )
		$page = 1;

	if ( $count &gt; $args&#091;&#039;range&#039;&#093; ) {
		if ( $page &lt;= $args&#091;&#039;range&#039;&#093; ) {
			$min = 1;
			$max = $args&#091;&#039;range&#039;&#093; + 1;
		} elseif ( $page &gt;= ($count - $ceil) ) {
			$min = $count - $args&#091;&#039;range&#039;&#093;;
			$max = $count;
		} elseif ( $page &gt;= $args&#091;&#039;range&#039;&#093; &amp;&amp; $page &lt; ($count - $ceil) ) {
			$min = $page - $ceil;
			$max = $page + $ceil;
		}
	} else {
		$min = 1;
		$max = $count;
	}

	$echo = &#039;&#039;;
	$previous = intval($page) - 1;
	$previous = esc_attr( get_pagenum_link($previous) );
	if ( $previous &amp;&amp; (1 != $page) )
		$echo .= &#039;&lt;a href=&quot;&#039; . $previous . &#039;&quot; title=&quot;&#039; . __( &#039;previous&#039;, FB_GREYFOTO_TEXTDOMAIN) . &#039;&quot;&gt;&#039; . $args&#091;&#039;previous_string&#039;&#093; . &#039;&lt;/a&gt;&#039;;
	$firstpage = esc_attr( get_pagenum_link(1) );

	if ( $args&#091;&#039;view_fp&#039;&#093; &amp;&amp; $firstpage &amp;&amp; (1 != $page) )
		$echo .= &#039;&lt;a href=&quot;&#039; . $firstpage . &#039;&quot;&gt;&#039; . __( &#039;First&#039;, FB_GREYFOTO_TEXTDOMAIN ) . &#039;&lt;/a&gt;&#039;;

	if ( !empty($min) &amp;&amp; !empty($max) ) {
		for( $i = $min; $i &lt;= $max; $i++ ) {
			if ($page == $i) {
				$echo .= &#039;&lt;span class=&quot;active&quot;&gt;&#039; . str_pad( (int)$i, 2, &#039;0&#039;, STR_PAD_LEFT ) . &#039;&lt;/span&gt;&#039;;
			} else {
				$echo .= sprintf( &#039;&lt;a href=&quot;%s&quot;&gt;%002d&lt;/a&gt;&#039;, esc_attr( get_pagenum_link($i) ), $i );
			}
		}
	}

	if ($args&#091;&#039;view_lp&#039;&#093;) {
		$lastpage = esc_attr( get_pagenum_link($count) );
		if ( $lastpage &amp;&amp; ($count != $page) ) {
			$count = str_pad( (int)$count, 2, &#039;0&#039;, STR_PAD_LEFT );
			$echo .= &#039;&lt;a href=&quot;&#039; . $lastpage . &#039;&quot;&gt;&#039; . __( &#039;Last&#039;, FB_GREYFOTO_TEXTDOMAIN ) . &#039;(&#039; . $count . &#039;)&#039; . &#039;&lt;/a&gt;&#039;;
		}
	}

	$next = intval($page) + 1;
	$next = esc_attr( get_pagenum_link($next) );
	if ($next &amp;&amp; ($count != $page) )
		$echo .= &#039;&lt;a href=&quot;&#039; . $next . &#039;&quot; title=&quot;&#039; . __( &#039;next&#039;, FB_GREYFOTO_TEXTDOMAIN) . &#039;&quot;&gt;&#039; . $args&#091;&#039;next_string&#039;&#093; . &#039;&lt;/a&gt;&#039;;

	if ( isset($echo) )
		echo $args&#091;&#039;before_output&#039;&#093; . $echo . $args&#091;&#039;after_output&#039;&#093;;
}
</pre>
<p>For use the function inside the templates use the follow syntax:</p>
<pre>
&lt;?php if ( function_exists(&#039;fb_paging_bar&#039;) ) fb_paging_bar(); ?&gt;
</pre>
<h4>Example for custom arguments</h4>
<p>For custom arguments, please use the filter. Also an example for this solution.</p>
<pre>
function change_fb_paging_bar_defaults($args) {

	$args&#091;&#039;previous_string&#039;&#093; = &#039;&#039;; // empty string
	$args&#091;&#039;next_string&#039;&#093; = &#039;&#039;;

	return $args;
}
add_filter(&#039;fb_paging_bar_defaults&#039;, &#039;change_fb_paging_bar_defaults&#039;);
</pre>
<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/2078/custom-pagination-without-wordpress-plugins/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hide The Comment Pagination</title>
		<link>http://wpengineer.com/1420/hide-the-comment-pagination/</link>
		<comments>http://wpengineer.com/1420/hide-the-comment-pagination/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 09:25:45 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1420</guid>
		<description><![CDATA[Ever since version 2.7 WordPress offers the option to adjust the number of comments on each page. From SEO's perspective, this is not very smart, as there were many articles and discussions about this topic in the past. If you turn off the comment pagination, the empty HTML fragment is still in the source code [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since version 2.7 WordPress offers the option to adjust the number of comments on each page. From SEO's perspective, this is not very smart, as there were many articles and discussions about this topic in the past. If you turn off the comment pagination, the empty HTML fragment is still in the source code of the page.<br />
<span id="more-1420"></span><br />
Unfortunately, the classes that respond with CSS are the same as those from the normal page and post pagination.<br />
If you have a theme in which the outer container of pagination has a frame or a background color, then you can see the empty container. Here are 2 screenshots with and without activated comment pagination to illustrate what I mean:</p>
<p><img class="aligncenter size-full wp-image-1422" title="Comment Pagination" src="http://wpengineer.com/wp-content/uploads/comment-pagination.jpg" alt="Comment Pagination" width="373" height="39" /><br />
<img class="aligncenter size-full wp-image-1423" title="Empty Comment Pagination" src="http://wpengineer.com/wp-content/uploads/empty-comment-pagination.jpg" alt="Empty Comment Pagination" width="373" height="39" /></p>
<p>Another annoyance would be if <code>.pagination</code> has a margin-bottom, which would also have a negative effect on the layout. What can you do about it?</p>
<p>WordPress stores the setting of the comment pagination in the database table options under page_comments. Value 1 means on, value 0 means off. By doing so you can hide the pagination in <strong>comments.php</strong> if it is not turned on:</p>
<pre lang="php">
&lt;?php if ((int) get_option(&#039;page_comments&#039;) === 1): ?&gt;
	&lt;div class=&quot;navigation&quot;&gt;
		&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_comments_link() ?&gt;&lt;/div&gt;
		&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_comments_link() ?&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;?php endif; ?&gt;
</pre>
<p>The query checks whether the comment pagination is set to (1) and displays the navigation. If it is set to (0) it will not display the navigation. On the other hand, if it is turned off, WordPress doesn't need to execute the two functions <strong>previous_comments_link()</strong> and <strong>next_comments_link()</strong>.<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/1420/hide-the-comment-pagination/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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>

