<?php
/**
 * The template for displaying the One Page.
 *
 * @package WordPress
 * @subpackage Omni
 * @since Omni 1.0
 */
 ?>

<?php
	// Get pages inside the wp menu to display
	if ( ($locations = get_nav_menu_locations()) && $locations['primary'] ) {
		
        $one_page_nav = wp_get_nav_menu_object( $locations['primary'] );
        $one_page_nav_items = wp_get_nav_menu_items( $one_page_nav->term_id );
        $nav_pages = array();
        foreach ( $one_page_nav_items as $item ) {
            if ( $item->object == 'page' )
                $nav_pages[] = $item->object_id;
        }
        $args = array(
			'post_type'			=> 'page',
			'post__in'			=> $nav_pages,
			'posts_per_page' 	=> count($nav_pages),
			'orderby'			=> 'post__in',
		);
		
    }
	
	$onepage_sections = new WP_Query($args);
	
	while ($onepage_sections->have_posts()) : $onepage_sections->the_post();
	
		// Display actual page
		get_template_part( 'content', 'page' );
		
		// Check if this page contains pages/seperators in the page sorter
		if (vp_metabox('omni_meta_pages.page_sorter')) {
			
			// Get page sorter array
			$get_insert_pages = vp_metabox('omni_meta_pages.page_sorter');
			$args_two = array(
				'post_type'			=> array('page', 'omni_asides'),
				'post__in'			=> $get_insert_pages,
				'posts_per_page' 	=> count($get_insert_pages),
				'orderby'			=> 'post__in'
			);
				
			$query_pages_seperators = new WP_Query($args_two);
			
			// Display the extra pages/seperators
			while ($query_pages_seperators->have_posts()) : $query_pages_seperators->the_post();
			
				get_template_part( 'content', 'page' );
			
			endwhile; wp_reset_postdata();
		}
		
	endwhile; wp_reset_postdata(); ?>