WP-Mix

A fresh mix of code snippets and tutorials

WordPress navigation outside the loop

Normally the template tags used for navigating posts and pages must be included inside of the WordPress loop. This is great but there may be times when you need to display the navigation links outside of the loop.

<?php if(is_single()) { // single-view navigation ?>
	<?php $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post(); ?>
		<?php previous_post_link(); ?> | <?php next_post_link(); ?>
	<?php endwhile; endif; ?>
<?php } else { // archive view navigation ?>
		<?php posts_nav_link(); ?>
<?php } ?>

Source

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress