0

I have a parent page called "About". This page has three child pages "Members", "Information", "Contact".

I want to list all the child-pages on all four pages, also the parent-page. So right now I have this which lists all the child-pages only on the parent-page.

<?php
        if ( !$post->post_parent ) {
            echo '<ul id="subpages" class="wrapper">';
                wp_list_pages("title_li=&child_of=".$post->ID."&link_before=— ");
            echo '</ul>';
        }
    ?>

But I want all the pages also listed on each individual child page.

How do I do that?

1

This function will do the trick, it displays the child pages of the current page, but if there are no child pages, it displays the child pages of the parent page, and a link back to the parent page.

/**
 * @brief: Shows the subpages of the current page, or
 *         the adjacent sibling pages.
 **/
function show_subpages(){

    global $post;
    $subpages = wp_list_pages( array(
        'echo'=>0,
        'title_li'=>'',
        'depth'=>2,
        'child_of'=> ( $post->post_parent == 0 ? $post->ID : $post->post_parent)
    ));
    if ( !empty($subpages) ) {

        if ( $post->post_parent != 0 ) {
            echo '<p class="parent-link"><em>'. __('Back to') .' <a href="'. get_permalink($post->post_parent) .'">'. get_the_title($post->post_parent) .'</em></a><p>';
        }
        echo '<ul>';
        echo $subpages;
        echo '</ul>';
    } else {
        echo 'no subpages';
    }
}

You may need to place this in the main loop

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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