Adjust order of nextPage/previousPage (3 posts)

  1. blakewaddill
    Posted 4 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:


    <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!

  2. Luke Rumley
    Posted 4 years ago #

    get_pages has a orderby=menu_order


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

  3. Michael
    Forum Moderator
    Posted 4 years ago #

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


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.