Support » How-To and Troubleshooting » Adjust order of nextPage/previousPage

Adjust order of nextPage/previousPage

  • I am working on a gallery site for a friend. The theme I am using uses child pages to populate each gallery. I am able to sort the order the images are displayed within the gallary; however, the next/previous buttons are navigate in alphabetical order instead of the order we specified. Here is the code for page.php and function.php that we are working with:


    <div class="pageNav clearfix">								<?php $previous_page = siblings('before'); ?>							<?php $next_page = siblings('after'); ?>


    function siblings($direction) {
        global $post;
    	if ($post->post_parent) {
    		$siblings = get_pages('child_of='.$post->post_parent.'&parent='.$post->post_parent);
        	foreach ($siblings as $key=>$sibling){
            	if ($post->ID == $sibling->ID){
                	$ID = $key;
    		if ($direction == 'before' && $siblings[$ID-1]->ID) {
    			$link = '<a class="previousPage" href="'.get_permalink($siblings[$ID-1]->ID).'">'.__('← Previous','themetrust').'</a>';
    			echo $link;
    		if ($direction == 'after' && $siblings[$ID+1]->ID) {
    			$link = '<a class="nextPage" href="'.get_permalink($siblings[$ID+1]->ID).'">'.__('Next →','themetrust').'</a>';
    			echo $link;

    My php is not very strong, but it appears to me that next/previous are using the page ID which is effectively causing the next/previous to navigate in alphabetical order.

    Is there a way to edit the function so the Page Attribute for “menu_order” is used to determine what is next/previous?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adjust order of nextPage/previousPage’ is closed to new replies.
Skip to toolbar