WP Pagenavi

WP-PageNavi: Version 2.80

The main feature in this version is the ability to use wp_pagenavi() for multipart pages.

For example, to add it to the Twentyeleven theme, you would open content-page.php and replace this line:

<?php wp_link_pages( array( 'before' => '

<div class="page-link">
  <span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '
</div>' ) ); ?>

with this:

<?php wp_pagenavi( array( 'type' => 'multipart' ) ); ?>

WP-PageNavi: Version 2.74

Two new improvements come with this version:

Using wp_pagenavi() with custom queries

The old way (which still works):

query_posts( array( 'tag' => 'foo', 'paged' => get_query_var('paged') ) );

while ( have_posts() ) : the_post();
	the_title();
	// more stuff here
endwhile;

wp_pagenavi();

wp_reset_query();	// avoid errors further down the page

The new way (better, because it has less side-effects):

$my_query = new WP_Query( array( 'tag' => 'foo', 'paged' => get_query_var('paged') ) );

while ( $my_query->have_posts() ) : $my_query->the_post();
	the_title();
	// more stuff here
endwhile;

wp_pagenavi( array( 'query' => $my_query ) );

wp_reset_postdata();	// avoid errors further down the page

Notice that, in both cases, I included the ‘paged’ parameter. Without it, you would see the same posts on all pages.

‘smaller’ and ‘larger’ classes

Each link has now an additional ‘smaller’ or ‘larger’ class, depending on where it is, in relation to the current page.

For example, if you’re on page 2, the link to page 1 will have the ‘smaller’ class, while links to page 3, 4, 5 etc. will have the ‘larger’ class.

This allows even more customization via CSS.

Enjoy.

WP-PageNavi: Version 2.70

PHP5 requirement

In order to run version 2.70 or newer, your host needs to be running PHP5. If you get a fatal error on activation, ask your hosting provider to upgrade your account from PHP4 (which is old, slow and a security risk).

To see what PHP version you’re really running, add this line to wp-config.php:

var_dump(PHP_VERSION);

You can get the earlier version of the plugin from here.

Enhancements

First of all, I’ve trimmed down the default pagenavi-css file so that it integrates better with your theme, out of the box.

If you don’t want to display a certain part of the navigation, like the “previous page” link, you can simply go to the Page Navigation Text section, on the settings page, and clear that field.

Also, you can now insert HTML code in those fields. This is useful if you want, for example, to display an image instead of the usual “»”.

The “Uninstall WP-PageNavi” section was removed. Cleanup will be performed automatically when you uninstall the plugin from the Plugins page.

Finally, If you need super-advanced customization, you can use the ‘wp_pagenavi’ filter.

WP-PageNavi: The Right Way To Use query_posts()

First rule of using query_posts(): don’t. Use the ‘request’ filter instead.

Ever since I’ve taken over development of the WP-PageNavi plugin, I keep seeing people opening support topics like this:

“PageNavi doesn’t show the correct posts”

“Page numbers don’t work with PageNavi”

etc.

Most of the time, your theme is just using query_posts() wrong.

So here is the correct way to make paging work using query_posts():

Say you have something like this:

query_posts('cat=8');

or like this:

query_posts( array( 'cat' => 8 ) );

You just need to pass along the ‘paged’ query var from the main query:

query_posts( array( 'cat' => 8, 'paged' => get_query_var('paged') ) );

If that doesn’t work, you can also try passing the ‘page’ query var:

query_posts( array( 'cat' => 8, 'paged' => get_query_var('page') ) );

Also see the Codex page on query_posts().