Sillybean
Next Page
This plugin provides shortcodes and template tags for next/previous navigation in pages.
Download it at wordpress.org »
Report problems using the support forum »
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');
141 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!
I just downloaded Next Page 1.5. I installed it in WP and activated it, but I don’t see it on my site at all. I did not play with any of the options as I don’t know what all that stuff is about. I’m a big noob. Can someone help me out??
great plugin!! not many like it.
i’m having one problem, assuming it’s a CSS thing. but could use a pointer all the same.
on the following link, you’ll see that the previous shows on the left, and then the “next” also shows on the left. i have it set for alignright in the settings, but it still goes to left.
here’s the link: http://www.meshweddingdesign.com/?page_id=229
here’s the section of code in that page template:
any pointers? thanks!
haha…there’s no better way to discover the solution than to post a comment on a developer’s blog with a question. found the solution w/in 5 minutes after writing question above. i needed to edit the code that goes before the tag to read “right” instead of “alignright” as that’s the wording in my stylesheet. easy enough. thanks for the great plugin!!!
Great plugin, however…
The exclude page id’s don’t seem to be working. Any ideas?
I noticed this too. I LOVE this plug in, so simple and works pretty much as I want.
The Exclude Pages works halfway – it doe snot show the “previous” on the page IDs, but it does still show the “next”
How do we get this to not show either?
Hello! Good plugin!
But for my project I have made one change in function flatten_page_list:
function flatten_page_list($exclude = ”) {
global $post;
$args = ‘sort_column=menu_order&sort_order=asc&hierarchical=0&parent=’.$post->post_parent;
…
Now naviagtion looks like navigation for posts in the same category.
You do not cycle through ALL pages, but only through pages that have the same parent page.
I’m using a plug in which show a post within another post. Most navigation plug ins don’t preserve page brakes in the original post when I show that post in another post.
The “Next Page” shortcode shows the previous and next links from the original post, but they go to my sites home page instead of previous and next pages in the post.
I’d really appreciate any advise. I’ve been struggling for a solution for a week.
Thanks.
Hi steph !
I had some problem under using “Next Page” plug-in.
I discussed in WordPress Forum Japan.
And then I get a solution about that !
See The URI follow.
http://ja.forums.wordpress.org/topic/5943?replies=6
I hope you will adopt this into your work, if you don’t mind.
Thanks for the plugin. What a life-saver!!
I made the following change:
$args = ‘sort_column=post_title&sort_order=asc’
I’m totally new to WP, so it took a bit of hacking and a bit of luck to find out why my stuff wasn’t paging correctly. Dunno if this affects anyone else…
I’m working on my first WordPress-based website and am trying to set up a previous / next page navigation on it. You will find my website at: http://www.gwendolinelamour.com/blog
I have tried your plugin, and your php code installed manually. In both cases I encounter the same problem: the page navigation links gets confused by the blog page. It appears to be confusing individual posts with static pages. I want the navigation to work for just the pages. Can you advise as to how to fix this?
Many thanks
Tim
I’m using this on pages as part of an itinerary with one page per day. It appears that this works only if pages are added in sequential order, as the code gets the next sequential pageid, not necessarily the next chronological day, even if the permalink structure is changed.
If I add Wednesday’s itinerary after Monday’s itinerary and then add Tuesday’s itinerary, it will not page correctly.
Any ideas?
Great plugin. Is there any easy way to make it so that it only goes to the previous/next page of a related child page (sibling page)? For example
Parent >
Child 1, Child 2, Child 3
I want it so that it only goes back and forth between Child 1, Child2 & Child 3.
Thanks!
I’d really like a similar structure too. Is it possible?
Same here. It’s showing on all pages even the ones I’ve excluded. Any thoughts?
Hi,
I’ve installed the plug-in and gone to Next Page Options.
I have no idea what to do next.
Cheers
Mark
Hi, Mark. You can use the shortcodes in a page’s content, or you can copy the template tags into your theme’s page template. Both the shortcodes and the template tags are shown on the options page.
Is it possible to target just the child pages for a parent page? I am working on a site that has hundred of pages, and it will be cumbersome to exclude.
Thanks!
Is it possible to have multiple instances of the navigaion on one page. I’m trying to put the prev/next navigation both before and after the content (because the content is really long) and I’m finding that the nav links at the bottom are not the same as the links at the top. Should that be happening?