Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks

share|improve this question
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... –  boscho May 20 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 –  JackTheKnife May 20 at 17:07

1 Answer 1

up vote 0 down vote accepted

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:

    <?php
$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>
</div>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>"><img src="arrow-right.png"></a>
</div>
<?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'); ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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