Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm not finding any info on this, so I'm probably wording it incorrectly in my search. So I'm hoping someone can point me in the right direction.

I have 50 pieces of content that'll be going on my wordpress site. Each piece of content will be broken down into 5-6 pages (each). So I made a custom page template for this.

My goal is to have a navigation that shows the child pages, so users can click through them easily to reference different sections of the content. But I don't want to do this manually per page.

I've tried searching for child-page navigations and the best I've come up with is a plugin that just lists the child-pages. This wont work because even on the child pages I want the navigation to show.

Any direction would be extremely helpful.

share|improve this question
add comment

1 Answer 1

I'm outlining a solution for you, it uses get_children to determine if there are any, then conditionally sets up the post id $p_id for the child_of parameter, so that the list of child pages from a certain parent always can be shown, by making use of wp_list_pages().

Code:

function wpse125273_child_page_nav() {
    global $post;

    $args = array( 
        'post_parent' => $post->ID,
        'post_type'   => 'page',
        'post_status' => 'publish'
    );
    $children = get_children( $args );

    if ( empty( $children ) ) {
        $p_id = $post->post_parent;
    } else {
        $p_id = $post->ID;
    }

    $args = array(
        'child_of' => $p_id,
        'post_type'   => 'page',
        'post_status' => 'publish'
    );
    wp_list_pages( $args );
}

Note: exemplary and untested

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.