Support » Themes and Templates » How to sort child pages on parent

How to sort child pages on parent

  • Hi!
    I have made a template for a one-page-scrolling website and i used the code found on this topic:
    to display child pages (with their templates-parts)

    global $wp_query;
    // is Page a parent page
    if ( $post->post_parent == 0 ) {
    	// on a parent page, get child pages
    	$pages = get_pages( 'hierarchical=0&parent=' . $post->ID );
    	// loop through child pages
    	foreach ( $pages as $post ){
    		setup_postdata( $post );
    		// get the template name for the child page
    		$template_name = get_post_meta( $post->ID, '_wp_page_template', true );
    		$template_name = ( 'default' == $template_name ) ? 'page.php' : $template_name;
    		// default page template_part content-page.php
    		$slug = 'page';
    		// check if the slug exists for the child page
    		if ( locate_template( 'content-' . basename( $template_name ) , $load, $require_once ) != '' ) {
    			$slug = pathinfo( $template_name, PATHINFO_FILENAME );
    		// load the content template for the child page
    		get_template_part( 'content', $slug );

    The contents from the different child pages are automatically ordered alphabetically, I am now looking for a way to sort them in the order defined in the back-office (‘Order’)
    here is the project i am working on:

    Thanks for your help…

  • The topic ‘How to sort child pages on parent’ is closed to new replies.