How To Build WP-PageNavi Into Your WordPress Theme

WP-PageNavi, from Lester “GaMerZ” Chan, gives you an awesome upgrade to your WordPress post-page navigation. Instead of the typical “Older Post/Newer Post” links, you get “Digg-like” pagination. Like so:

Wp-PageNavi Sample

Very cool. But what if you want to incorporate it into a WordPress theme for release? How do you style it when the instructions tell you to modify the plugin files? Good questions. I’ll tell you how.

First of all you want to tell WordPress to use the plugin if it’s installed and if it’s not installed to use the traditional navigation.

<?php if(function_exists('wp_pagenavi')) { // if PageNavi is activated ?>

<?php wp_pagenavi(); // Use PageNavi ?>

<?php } else { // Otherwise, use traditional Navigation ?>

<div class="nav-previous">
<!-- next_post_link -->
</div>

<div class="nav-next">
<!-- previous_post_link -->
</div>

<?php } // End if-else statement ?>

Good. Now for the styling. To edit the styles of the Page Navi plugin simply copy pagenavi-css.css into your theme directory folder and make your changes there. That way you won’t lose any changes when you upgrade the plugin.

You can look for this technique in some of my future themes. Good luck trying it out in yours!

Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

About Ian Stewart

Ian Stewart is probably thinking about WordPress Themes this very minute. Don't forget to follow him on twitter.

18 Comments

  1. Posted April 26, 2008 at 1:28 am | Permalink

    Thank you. I hadn’t heard of this plugin. I also experienced something of an epiphany when you wrote, “Now your styles are protected against any upgrades to the plugin….”

    Now, why didn’t I think of that before.

  2. Posted April 26, 2008 at 7:49 am | Permalink

    I hope that isn’t because you’ve done things the hard way. Or even worse, the pull my hair out because everything is broken and there goes the weekend way.

    … I would of had that moment last week, thanks to Subversion, if it wasn’t for the Mac Time Machine. Love that thing. No Morlocks involved or anything.

    Anyway, WP-PageNavi. Yeah, it’s awesome. I’m going to start using it here when I switch to using Thematic. Which is, not incidentally, all about protecting your site against any upgrades.

  3. Erin
    Posted May 16, 2008 at 12:16 pm | Permalink

    Thanks Ian. These are the the missing instructions in Lester Chan’s documentation.

  4. Posted May 17, 2008 at 9:39 am | Permalink

    Glad to be useful, Erin.

  5. Posted June 24, 2008 at 12:47 am | Permalink

    Hi, I have been searching for this plugin for a long time….

    Thanks for sharing this one….

    You can check this working on my blog:
    http://www.naseerahmad.com/

  6. Posted July 1, 2008 at 11:50 am | Permalink

    I actually said ‘ooh that’s a bit clever’ out loud in my office. Oh dear.

    :-) Thank you for this fantastic tutorial.

  7. Posted October 29, 2008 at 4:36 pm | Permalink

    How do you change the number of posts to consider before paging starts. It looks like the default is 10 and I wanted to move that to a higher number. Any idea where to change that magic number. I’ve looked into the source code and couldn’t find the appropriate place to make that change.

  8. Posted October 30, 2008 at 8:42 pm | Permalink

    i want to paginate my theme in a digg like way, i have several premium thems i am willing to share theme if some one tells me how to paginate my them.

    leave me a comment on my site: http://emediagallery.com

  9. slobjones
    Posted December 16, 2008 at 9:30 pm | Permalink

    This thing creates a mess in IE because of the way IE abuses padding. The boxes are waaaaaaaaay to wide.

    If anyone has figured out a solution, please post it.

  10. Posted January 13, 2009 at 12:56 pm | Permalink

    This is a fantastic post, it is exactly what I searched every where for, thanks alot :)

  11. Posted March 22, 2009 at 7:28 pm | Permalink

    Thanks for filling in the gaps on this, Ian. To fix the extra wide spacing in IE, you need to edit wp-pagenavi.php and remove the non-cross-browser-compliant “ ” references (the html character entity for thin space) from lines 113 to 138. Wasn’t able to override it with CSS so sadly, yes, you will have to do this each time you upgrade the plugin.

  12. Posted April 16, 2009 at 11:56 am | Permalink

    Thank you for this wonderful tip! I just wish I’ve read this article before I edited the CSS in the plugin folder! hahaha. Thanks!

  13. Posted April 24, 2009 at 6:18 pm | Permalink

    Where should i put these codes? the usage doc, says put in the footer. but that would be silly since it would appear everywhere in the blog and not just in the single posts.

  14. Anu
    Posted July 30, 2009 at 12:59 pm | Permalink

    Would this work with any plug in?

    I am trying to incorporate WP-Print into my theme and set print options as in this sample

    http://simplyrecipes.com/recipes/spicy_citrusy_black_beans/

    Know just a little php to be dangerous not enough to be useful.

    Your help is appreciated.

    Thanks

  15. RB
    Posted December 10, 2009 at 12:25 am | Permalink

    Hi,

    Does it work for pages or it works with post only? I tried using it with page, it didn’t work. Can you please tell me on what basis it inserts a page break in a page? I m very confused. I want to use it on page: http://delhi-masterplan.com/news-articles/ only. Can you please help? Tks

  16. Posted March 4, 2010 at 9:50 pm | Permalink

    Thanks for this post.

    I’ve been looking for a way to do this for a while. Glad to finally find a solution!

  17. Posted April 14, 2010 at 3:54 pm | Permalink

    Great Article, simple and efficient way to implement this plug-in. I will most likely be putting it on my website as well: http://www.dlocc.com

    Bookmarked your site… great WordPress stuff on here.

  18. Ant Gray
    Posted June 5, 2010 at 3:59 pm | Permalink

    Not sure if this pagination design is usable. Buttons (especially next and previous pages) should be bigger.

    /* POV of blog reader */

4 Trackbacks

  1. By links for 2009-02-23 « jasonmcdermott.net on February 23, 2009 at 6:01 am

    [...] How To Build WP-PageNavi Into Your WordPress Theme Very cool. But what if you want to incorporate it into a WordPress theme for release? How do you style it when the instructions tell you to modify the plugin files? Good questions. I’ll tell you how. (tags: wordpress tutorials) [...]

  2. By Daily Digest for May 22nd | Digital Gilbert on May 23, 2009 at 12:23 am

    [...] How To Build WP-PageNavi Into Your WordPress Theme [...]

  3. [...] 本文翻译自:ThemeShaper.com [...]

  4. [...] 本文翻译自:ThemeShaper.com [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution. In addition, you may find yourself fitter, happier and more productive. Comment away.

Subscribe without commenting