WordPress.org

Ready to get started?Download WordPress

Forums

CMS Tree Page View
Sort Order numbering (2 posts)

  1. mores
    Member
    Posted 1 year ago #

    Can you explain, how the sort order is being processed?

    My problem:
    I'm using a function to automatically display the next page in line.
    It's very complex since we're using CPTs, but somehow the function uses the next higher order number and seems to ignore the hierarchy.

    Let me see if I can paste it here

    function get_next_page_id( $current_page_id, $prev_or_next = 'next' ) {
    	if ( empty( $current_page_id ) )
    	return false;
    
    	$posts_ancestors = get_post_ancestors($current_page_id);
    	if ($posts_ancestors)
    	{
    		$post_parent = $posts_ancestors[0];
    	}
    
    	// No parent, aka Modul StartPage
    	if  ( !$post_parent )  {
    		// exclude current page, set post_parent
    		$args = array(
    			'post_type' 	=> 'elearning',
    			'numberposts' 	=> -1,
    			'post_status' 	=> 'publish',
    			'orderby' 		=> 'menu_order',
    			'order' 		=> 'ASC',
    			'exclude'		=> $current_page_id,
    			'post_parent'   => $current_page_id,
    			'tax_query' => array(
    			array(
    				'taxonomy' => 'el_page_types',
    				'field' => 'slug',
    				'terms' => array( 'sidebar', 'zusatzinfos', 'befunde', 'status'),
    				'operator' => 'NOT IN'
    				)
    		),
    		);
    		//print_r ('nopostparent'); 
    
    	} else {
    		$args = array(
    		'post_type' 	=> 'elearning',
    		'numberposts' 	=> -1,
    		'post_status' 	=> 'publish',
    		'orderby' 		=> 'menu_order',
    		'order' 		=> 'ASC',
    		'tax_query' => array(
    			array(
    				'taxonomy' => 'el_page_types',
    				'field' => 'slug',
    				'terms' => array( 'sidebar','zusatzinfos', 'befunde' ,'status'),
    				'operator' => 'NOT IN'
    				)
    		),
    		);
    	}
    
    	$posts_array = get_posts( $args );
    
    	$pages = array();
    	foreach ($posts_array as $page) {
    		$pages[] += $page->ID;
    		}
    
    	$current = array_search($current_page_id, $pages);
    
    	$prevID = $pages[$current-1];
    	$nextID = $pages[$current+1];
    
    	//print_r ($pages);
    	/* print_r($pages);
    	print_r ($current_page_id);
    	echo('next: '. $nextID);
    	*/
    
    	//$next_page_link = '<a href="#" class="next_page"><span>Weiter<span></a>previous: '.$prevID.' - next: '.$nextID.' -end';
    	//print_r  ($pages);
    
    	if ($prev_or_next == 'next') {
    		if (!$post_parent)  {
    			return  $pages[0];
    		} else {
    			$modul_id = get_modul_page_id($current_page_id);
    			if ( $modul_id == get_modul_page_id($nextID) )  {
    				return $nextID;
    				} else {
    					//print_r($pages[$current]);
    					return $nextID;
    				}
    		}
    
    	}   else  { return $prevID; }
    }
    function echo_next_page_id( $current_page_id) {
    	echo ('<a href="' . get_post_permalink(get_next_page_id($current_page_id, 'next')) .'" class="next_page"><span>Weiter</span></a>');
    }
    function echo_prev_page_id( $current_page_id ) {
    	echo ('<a href="' . get_post_permalink(get_next_page_id($current_page_id,  'prev')) .'" class="prev_page"><span>Zur&uuml;ck</span></a>');

    So when I drag Pages around, they're looking good in TreeView, but the child of a page with the order "5" may have the order of "99".
    THis works for treeview, but not for my template script.

    Any help you can give me?

    http://wordpress.org/extend/plugins/cms-tree-page-view/

  2. mores
    Member
    Posted 1 year ago #

    Honestly, what I wish for is for a plugin that will re-order my pages (or CPTs) properly.
    The first one will be order #1. The second one order #2. Etc.
    Now, every time I drag the pages around, the order numbers increase!

    Can't we all just start with 1?

    :)

    I mean, TreeView is awesome. It's drag/drop functionality is simple and powerful, adding X pages at a time is a breeze, I really appreciate the app. But it messes up the order by obviously just looking at the highest order-number and one-upping it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.