thanks for taking a minute to read my question. I've done some googling and I can't seem to find the answer to this question anywhere. Forgive me if it's somewhere here on stack exchange already.

I'm using this plugin to allow "< prev" and "next >" links in my set of pages. I can change the page order using the wordpress admin menu, so this is almost perfect. However, I have a couple of pages I would like to skip in the "previous" and "next" loop.

For instance - I'm using a static home page. At one point, the "next" link links over to the home page. I'd like to exclude the home page and a couple others from this loop. Is this possible? What's the best way to do this?



P. S. The plugin works pretty much the same way as Next/Prev post built-in functionality works. I'm assuming if there's a way to exclude posts from this loop, that it will work the same way for pages with the plugin. Thanks

1 Answer 1


Haven't checked the plugin you mention... but I use this solution for doing an "author" navigation.

I adjusted the functions and this should probably work without the plugin (untested). You need to adjust the ID, and the conditions itself if you want more exclusions.

[edit: corrected functions, the queries were missing the menu_order condition]


1) the ID 99999 corresponds to the static page defined as Front Page

2) all pages must have a defined menu order, i believe if there are pages with 0 (zero) as menu order this won't work


function get_next_page_nav($link="%link", $title="%title") {
    global $wpdb, $post;
    $prev = $wpdb->get_row($wpdb->prepare("SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID!='99999' AND menu_order < '".$post->menu_order."' ORDER BY menu_order DESC LIMIT 1;"));
    if($prev) {
        $title = preg_replace('/%title/',$prev->post_title, $title);
        echo preg_replace('/%link/', '<a href="'.get_permalink($prev->ID).'" rel="prev" class="next-page">'.$title.'</a> ', $link);

function get_prev_page_nav($link="%link", $title="%title") {
    global $wpdb, $post;
    $next = $wpdb->get_row($wpdb->prepare("SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID!='99999'  AND menu_order > '".$post->menu_order."' ORDER BY menu_order ASC LIMIT 1;"));
    if($next) {
        $title = preg_replace('/%title/',$next->post_title, $title);
        echo preg_replace('/%link/', ' <a href="'.get_permalink($next->ID).'" rel="next" class="previous-page">'.$title.'</a>', $link);
  • I'm testing this out today - thanks so much for taking the time to answer this question. I'll get back to you if I have any questions - thanks!
    – timshutes
    Commented Apr 18, 2012 at 0:09
  • can you explain what you mean by "adjust the ID" - do you mean for the ID!='99999' exclusion? Or is there something else I need to adjust? I tried this as is and it's not working quite right. The 'next page' and 'previous page' links go to the same pages (contact us and home) no matter what page I'm on
    – timshutes
    Commented Apr 18, 2012 at 0:44
  • yep, sorry, there's a condition missing in the query AND menu_order < '".$post->menu_order."', but it's not working perfectly, i'm doing real tests and report back
    – brasofilo
    Commented Apr 18, 2012 at 1:06
  • Tested and working. I've updated the functions and put a couple of usage notes.
    – brasofilo
    Commented Apr 18, 2012 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.