I have on the site navigation menu which uses next/previous functionality to navigate through the site. Currently it is a hard coded image map with related links on each page.

I know how to get next/previous functionality from breadcrumbs to work for sub-pages following code from here , but I have no idea how to get that functionality to work between parent (top) menus, when there is no sub-pages or to jump to next parent (top) menu when landing page is a last sub-page.

Any tips?


  • 1
    Presumably, you wish for the next/previous links to move the user through the site according to the order of the items in the navigation menu. I don't think you should be looking at breadcrumbs NOR WordPress's prev/next links (which will navigate items according to the order they appear in the query). Were I you, I would parse nav_menu_items to determine the next and previous items. The way I see it, this question has absolutely nothing to do with breadcrumbs...
    – bosco
    May 20, 2014 at 16:44
  • I have used next/previous functionality from mentioned breadcrumbs to get similar functionality. I will reconsider your suggestion as another solution. BTW - if there are posts I need to have them present in the nav_menu_items to navigate through them? Thanks May 20, 2014 at 17:07

1 Answer 1


After some additional research it looks like it will require to use two separate methods to get next/previous page/post to work.

More here,here and here

Solution for pages:

$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
   $pages[] += $page->ID;

$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>"><img src="arrow-left.png"></a>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>"><img src="arrow-right.png"></a>
<?php } ?>
</div><!-- .navigation -->

solution for posts

<?php previous_post(' %', '<img src="arrow-left.png" alt="Next" border="0" align="right" />', 'no'); ?>
<?php next_post(' %', '<img src="arrow-right.png" alt="Next" border="0" align="right" />', 'no'); ?>

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.