Lego2012
12/13/2016 - 4:48 PM

List Child Pages

List Child Pages

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

<!-- In a template file or a PHP widget: -->

global $post; // Setup the global variable $post
if ( is_page() && $post->post_parent ) // Make sure we are on a page and that the page is a parent
    $kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
    $kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
 
if ( $kiddies ) {
    echo '<ul class="secondary">';
        echo $kiddies;
    echo '</ul>';
}

<!-- Genesis specific example: -->

add_action( 'genesis_before_entry', 'tgm_secondary_navigation' );
/**
 * This function adds an unordered list of child pages right before the post content in Genesis.
 *
 * @global object $post The current post object
 */
function tgm_secondary_navigation() {
 
    global $post; // Setup the global variable $post
 
    if ( is_page() && $post->post_parent ) // Make sure we are on a page and that the page is a parent
        $kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
    else
        $kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
 
    if ( $kiddies ) {
        echo '<ul class="secondary">';
            echo $kiddies;
        echo '</ul>';
    }
 
}