Skip to content

Instantly share code, notes, and snippets.

@dabernathy89
Created March 17, 2015 16:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabernathy89/42a8641f82720a1d71a4 to your computer and use it in GitHub Desktop.
Save dabernathy89/42a8641f82720a1d71a4 to your computer and use it in GitHub Desktop.
WordPress custom posts navigation function
<?php
// Adapted from Underscores' posts navigation function
// Uses Bootstrap classes
// In a default query:
// custom_posts_navigation();
// In a custom query:
// custom_posts_navigation($my_custom_query);
function custom_posts_navigation($custom_query = null) {
$max = is_null($custom_query) ? $GLOBALS['wp_query']->max_num_pages : $custom_query->max_num_pages;
if ( $max < 2 ) {
return;
}
?>
<nav class="navigation posts-navigation" role="navigation">
<h2 class="screen-reader-text">Posts navigation</h2>
<ul class="nav-links pager">
<?php if ( get_next_posts_link('', $max) ) : ?>
<li class="previous"><?php next_posts_link('Older posts', $max); ?></li>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<li class="next"><?php previous_posts_link('Newer posts'); ?></li>
<?php endif; ?>
</ul><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment