This is the default starting point for all my custom client themes. I use it as an included file _nav_posts.php
. Below is the entire contents of that included file.
<?php
/**
* Display navigation to next/previous pages of posts when applicable
* DRY include/partial
*
* Note that by default this also includes a list of the 5 most recent posts
* immediately following the previous/next.
*
* nav
* ul
* li
*
* @author zoe somebody
* @link https://beingzoe.com/zui/wordpress/kitchen_sink/
* @license https://en.wikipedia.org/wiki/MIT_License The MIT License
* @package KitchenSinkHTML5Themes
* @subpackage TwentyEleven
* @version 0.1
* @since 0.1
*/
if ( $wp_query->max_num_pages > 1 ) {
?>
<div class="wp_next_previous_more clearfix" role="navigation">
<ul>
<li class="previous"><?php next_posts_link( '<strong><span>←</span> Older posts:</strong>' ); ?></li>
<li class="next"><?php previous_posts_link( '<strong>Newer posts:<span>→</span></strong>' ); ?></li>
<li class="more">
<span class="more_title">Other recent posts...</span>
<ul>
<?php
$next_post = get_adjacent_post(true,'',false);
$previous_post = get_adjacent_post(true,'',true);
if ( $next_post && $previous_post )
$exclude = $next_post->ID . "," . $previous_post->ID;
else if ( $next_post )
$exclude = $next_post->ID;
else
$exclude = $previous_post->ID;
$featured_posts = get_posts("numberposts=5&exclude=$exclude");
foreach($featured_posts as $post) {
setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } ?>
</ul>
</ul>
</div>
<?php }
And here is the css to make that work:
/* Next, Previous, more navigation */
.wp_next_previous_more {
clear: both;
margin-top: 3em;
margin-bottom: 3em;
}
.wp_next_previous_more ul {
list-style: none;
padding-left: 0;
}
.previous, .next {
margin: 0 0 36px;
width: 45%;
}
.previous { float: left; padding-left: 18px; }
.next { float: right; padding-right: 18px; text-align: right; }
.previous span { margin-left: -18px; }
.next span { margin-right: -18px; }
.wp_next_previous_more .more ul {
/* Make this second level be a proper list again */
list-style-type: disc;
padding-left: 18px;
}
.wp_next_previous_more .more_title {
clear: both;
display: block;
/* h2 properties */
font-size: 20px; line-height: 36px; margin-top: 36px;
margin-bottom: 0em; font-weight: bold;
}
I also have a second file _nav_post.php
that I include under the content in single.php that does the same thing for next/previous post to post navigation.
I hope that is enough information to get you going. If you have questions just ask.
And you can see the a demo of it in action here.
—
Edit: Changed the nav tags in the sample code to div’s so as to not mess people people up with HTML5 junk ??