• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →

Stephanie Leary

Writer, WordPress consultant, recent MLIS grad

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

Next Page

This plugin provides shortcodes and template tags for next/previous navigation in pages. This plugin is no longer supported! If you would like to adopt it, please get in touch.

download at wordpress.org get support at wordpress.org donate to future development

If you’d rather not deal with the overhead of a plugin, here’s the condensed code for your page template file:

<?php
$pagelist = get_pages('sort_column=menu_order&#038;sort_order=asc');
$pages = array();
foreach ($pagelist as $apage) {
   $thepages[] += $apage->ID;
}

$current = array_search($post->ID, $thepages);
$prevID = $thepages[$current-1];
$nextID = $thepages[$current+1];
?>

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>"
  title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>"
 title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div><!-- .navigation -->

You can emulate Drupal’s book feature and include a link to the page parent as well:

<div class="aligncenter">
<a href="<?php echo get_permalink($post->post_parent); ?>"
 title="<?php echo get_the_title($post->post_parent); ?>">Up one level</a>
</div>

Version 1.2 adds an option to exclude pages by ID. You can simply add the exclude parameter to the get_pages() function in your template code:

$pagelist = get_pages('sort_column=menu_order&sort_order=asc&exclude=6,21,47');
You are here: Home / Code / WordPress Plugins / Next Page

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2023 Stephanie Leary · Contact