How to include prev/next navigation only when excerpts extend beyond one page

Posted in wordpress

If you don’t have enough blog posts to warrant previous/next page navigation, here is some simple code to include in index.php. This will prevent a broken link to a prev/next page that doesn’t yet exist.

<?php
  global $wp_query;
  $total_pages = $wp_query->max_num_pages;
  if ($total_pages > 1){
  include (TEMPLATEPATH . ‘/inc/nav.php’ );
}
?>