WordPress.org

Ready to get started?Download WordPress

Forums

Adjust order of nextPage/previousPage (3 posts)

  1. blakewaddill
    Member
    Posted 2 years ago #

    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:

    page.php

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

    functions.php

    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!

  2. Luke Rumley
    Member
    Posted 2 years ago #

    get_pages has a orderby=menu_order

    http://wordpress.stackexchange.com/questions/2969/order-by-menu-order-and-title

    Does that help? Typing and pasting on my phone, sorry!

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    try to include the parameters 'sort_order' and 'sort_column' into the code of get_pages()

    http://codex.wordpress.org/Function_Reference/get_pages

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.