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&#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');
141 comments

Sharing this post? The short URL is: http://sillybean.net/?p=2275

141 Responses to “Next Page”

  1. Ed says:

    Sorry. Cannot help you with that. Have not encountered that problem so far. Could be a browser issue, maybe?

  2. Tracy says:

    It’s not a browser issue that I can see. I’ve tried it on Firefox, Safari and Opera so far and all three have the same problem.

    Thanks for trying to help.

  3. Stephanie says:

    It is not a browser issue. I think I’ve identified the problem, but I’ve been swamped at work today and haven’t had time to test it. Tracy, try changing the $page variable to something else. Apparently it’s a global in WP, which I’d never noticed, and I’m pretty sure that’s the problem.

  4. Tracy says:

    That’s funny, Stephanie, I was just identifying that as the problem! Yeah, it’s used extensively in the post-template.php file.

    I changed both the $pages and $page variables and it worked.

    Thanks for spending the time to troubleshoot!

  5. Ed says:

    @Tracy what did you change them to? Will be nice to know for future reference in WP.

  6. Tracy says:

    @Ed I just changed them to $projectpage and $projectpages respectively because those names mean something to my specific pages. You can change them to whatever you want to though. Just make sure to change the name of all instances of each variable. (I didn’t change the $pagelist variable.)

  7. Stephanie says:

    I’ve just updated this page with better variables. Thanks for pointing out the problem, Tracy!

  8. Ed says:

    Thanks @Stephanie and @Tracy for all the help.

  9. Tracy says:

    Glad to have a problem that could help everyone! Thanks @Stephanie for your help.

  10. Ed says:

    Thank you for sharing it with us. This way we all get to learn new things.

  11. Simon says:

    it was[sic] nice to come to a dead stop at the first chapter or the last, instead of leaking over into the next book’s hierarchy.

    I’ve made 2 changes to this plugin:

    I too ran into the same issue as what Derek states an I think (imho) this in an improvement:

    Slightly changed Code

    The other thing is that I’ve removed the echos from the template tags. Lines 244,248,252 as I want to move the navigation outside the loop. You can put them back in if you wish.

    Hope this helps someone. Excellent plugin!

  12. Ed says:

    Thanks a lot Steph. Just upgraded it today. Will let you know if I run into any problems.

  13. Ed says:

    Are you using the script in your HTML to activate it?

  14. Eduardo says:

    Hello, I recently upgraded from v. 1.3 to 1.4, and now the previous and next links appear at the top of the page and there’s a weird rendering where the body text wraps around the previous and next links. Check it out:

    http://www.naborsapts.org/residents/co-op-handbook/home-equity-loan-or-line-of-credit/

    I’m using the shortcodes at the end of the text.

    Any help to fix the glitch appreciated.

    Cheers!

  15. Ed says:

    @Eduardo I do not see what you seem to say. I visited the website.

    • Eduardo says:

      The previous and next links used to be after the text of the page, which is where I want it. Now, after upgrading to 1.4, the links appear after the entry title, but before the text. Also, notice how the beginning of the text is squeezed (wraps around) the previous and next links. I hope this makes sense.

  16. Ed says:

    Can you post a link to the page so I know where to look?
    Thanks.

  17. Ed says:

    You can specify where you want the tags. Up or down on the page. Think there is an option in the settings to do it.

  18. Ed says:

    What version of WP are you using?

  19. Ed says:

    Then you should not have a problem. Could be a scripting issue. Who do you host with?

    • Eduardo says:

      The problem began when I upgraded from v. 1.3 to v. 1.4. So the logical conclusion is that something was changed in the plug-in code from 1.3 to 1.4. I’ll just go back to v. 1.3 and hopefully that’ll solve the problem. But thanks for trying, Ed!

  20. Ed says:

    See if that works. It should I think. Your script is messed up somewhere.

  21. Similar problem here – I have put the [previous] and [next] tags at the bottom of each of the site’s history pages but now the links appear at the top.

    Andrew

  22. Ed says:

    When I had the issue it was the script in my template that was over-riding the position of the text. Do you have any other modules in WP installed like WP Page Navi or something? Check your template index file too for scripting conflicts.

  23. Spiritualight says:

    Hi

    Im using the shortcodes with next page plugin. It doesnt matter where I put the short codes they always show up at the top of the page above all content. Is there a way of making the next and previous links show up after the content? I can see that this issue has possibly started since the 1.4 release? Where can I get version 1.3 to test and see if that solves it?

    Thanks

  24. Ed says:

    Not sure about the older version. It should be there on the site. Did you save a copy on your machine?

  25. Spiritualight says:

    Hi

    I found the older version and it works perfectly. The shortcode tags go where I put them and don’t just show up at the top of the page. I’ll be using 1.3 until 1.4 is fixed. Good plugin.. thanks

  26. Ed says:

    Sorry could not be of much help. Reverting back to the old version should help for now. The new one had some neat features.

  27. Jack says:

    I’m using the plugin for a site which has kind of a storyline.

    The parent pages are only container pages, containing two to ten subpages. These parent pages should not come up in the navigation. But when I enter those ID’s, no page whatsoever comes up because also the childpages are excluded.

    So:

    A
    a1
    a2
    a3
    B
    b1
    b2
    b3

    Pages A and B are empty. The navigation should go from a3 to b1. How can I do this?

  28. Melanie says:

    The links are not taking me to the next or previous page, just reloading the page I am already on.

    I would also like to use an arrow image to change pages instead of text. Can I do that??

    Take a look at my page!!

    http://www.adaytoremembervideos.com/david/

    THANKS

  29. Ed says:

    You can use arrows if you wish. You have to upload their image and use the appropriate script to do so.

  30. jack says:

    I’d like to put my question here for a second time, because the site is now online and I don’t know how to fix my problem (link: http://sillybean.net/code/wordpress/next-page/comment-page-2/#comment-22121). The problem is that the backlinks to previous pages is not working in my case. They link to the parent page which is empty, and than nothing happens.

    You can see what I mean here: http://www.onschuldiggevangen.nl/wat-ging-aan-pim-overziers-dood-vooraf/het-verhaal-van-pim-overzier

  31. Ed says:

    You might need to use an older version of the plugin as it seems there might be bugs in the new one.

  32. Ryan says:

    i am having a few problems with this plugin. When i add [previous] [parent] and [next]. [previous] and [parent] are grouped together on the same line while [next] is down a line and looks correct. Also i am trying to skip a sub-parent page but not skip the pages under the sub-parent page. is there a way to do that?

  33. Ed says:

    I am not exactly sure of what you mean.

  34. Ed says:

    Have you tried switching to an older version of the plugin?

  35. jack says:

    I tried version 1.3 and 1.2. Both don’t work.
    In my example above (http://sillybean.net/code/wordpress/next-page/comment-page-2/#comment-22121) I can go from a3 to b1 with no problem, but the backlink from b1 to a3 doesn’t work, because it wants to show B, which is empty.

  36. Ed says:

    I am not sure if the plugin is having problems with the alphanemeric characters you are using. Probably.

  37. jack says:

    Those numbers were just to illustrate the problem I’m having :) . In reality those are just titles of pages: http://www.onschuldiggevangen.nl/wat-ging-aan-pim-overziers-dood-vooraf/het-verhaal-van-pim-overzier

  38. Ed says:

    What version of WP are you using? It is working fine for me. What browser are you using?

  39. jack says:

    Version 2.9.2.
    I’m also using the plugin ‘redirect parent to first child’, but when I disable that plugin, I can go back from b1 to a3 through B, but B is empty. So before getting to page a3 I have to navigate paste an empty page. And I was using this plugin because when I click on parent page B, I want to see b1, and not B, because that’s only a placeholder for the subpages.

    I hope you see my ‘problem’.

  40. jack says:

    And I’m using Firefox, latest version. I forgot to mention that ;)

  41. Ed says:

    I am using IE 8.0 and it was working fine there.

  42. jack says:

    Strange. Google Chrome gives me the same problem. I wonder if I made clear enough what my problem is :( I can’t imagine it has something to do with what browser one uses.

  43. Ed says:

    The reason I suspected the browser was because I have seen it make a difference in reading HTML code.

  44. jack says:

    Do you think there can be some kind of fix for this? I mean, Internet Explorer is still the browser that is known to be not always correct in handling code and css, no matter what version.

  45. Ed says:

    Attach the code you are using as a text document. I will try to fix it for you.

  46. jack says:

    The code:

    http://www.spoenk.nl/public/page.txt

    The rest is all inside the plugin.

    Also: http://www.spoenk.nl/public/parent_to_first_child.txt
    because I’m using that for the direct link from parent to first child, but like I said, it didn’t have any effect disabling that plugin.

    Is this what you need?

  47. Ed says:

    Will let you know of the outcome after I test it out myself.

  48. Ed says:

    The code might need to be looked at.

  49. Xoxo says:

    Hello!

    Nice plugin and useful by the way… I need to navigate between custom post types. Can this be done?

    Thank you!! :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>