WP-PageNavi & Posts_Nav_Link in WordPress

I’ve been using the built in posts_nav_link tag in WordPress now for a while to do paged navigation. It will provide links for next and previous pages wherever you place it in your theme but will do nothing more, ie: (&#171 previous next &#187). I wanted something that would provide better pagination and found a great plugin called WP-PageNavi by Lester Chan which provides a more advanced paging navigation, ie: (Page 1 of 10: [1] 2 3 4 » … Last »).

The problem was I wanted to use the WP-PageNavi plugin but be able to fall back to Post_Nav_Link if the plugin was disabled or not running for whatever reason so the site wouldn’t be without navigation. The solution is using both tags in an if/else statement and placing it in your theme wherever you want the navigation to appear. Below is the code I am using to do it, hopefully someone can get some use of it.

<?php if (function_exists('wp_pagenavi')) { wp_pagenavi(); } 
else {echo '<div class="alignleft">';posts_nav_link('','','&laquo; Previous Entries'); 
echo '</div><div class="alignright">';posts_nav_link('','Next Entries &raquo;',''); 
echo '</div>'; } ?>

One thought on “WP-PageNavi & Posts_Nav_Link in WordPress”

Comments are closed.