Sillybean
Next Page
This plugin provides shortcodes and template tags for next/previous navigation in pages.
Download it at wordpress.org »
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&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');
123 comments
Sharing this post? The short URL is http://sillybean.net/?p=2275






Has anyone tested the plugin on WP 3.0 yet?
The plugin works fine in 3.0.
The problem with the links moving to the top after the 1.4 upgrade is just a CSS issue. If you’re using the alignleft and alignright classes (the default settings), they’re floated left and right, and that pushes them to the top with your content in between. You can fix the problem by either using different classes with different styles, or you can place a clearing element between your content and the next/previous links. For example, you could add <br style=”clear: both”> in front of your before-the-previous-link code.
I’m still swamped. As soon as I get a few minutes, I’ll release an update that includes an option to insert the clearing tag.
Thanks for doing that. I thought so too that it was a CSS issue.
I noticed a small bug in version 1.4. Your functions for placing the links echo the results instead of properly returning the results. Therefore, if you use the shortcodes, the links might show up before the content instead of where the shortcodes are placed. I assume calling the functions directly in PHP would result in expected behavior, though.
Anyway, thanks for writing the plugin. Hope this helps.
Everyone, look for version 1.5 in a few minutes. It includes fixes for all the bugs that were reported in 1.4, plus a Belorussian translation by Marcis Gasuns. Thanks for all your comments, and your patience!