WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, suppose a menu like so:

Parent 1
  Child A
  Child B
Parent 1
  Child C
  Child D
  Child E
Parent 2
  Child F

In a certain part of my template, I want something to show depending on the current "location" in the menu. If the user is on the Parent 1, Child C, Child D, or Child E pages, then I want a little menu to show up that says Parent 1 as the header and the children as the links. I've tried a variety of things (creating a custom walker object, writing css to just not show the items that shouldn't show, etc.) Also, if there are no children at all, then I don't want to display the parent even on the parent's own page. Does this make sense?

I don't want a plugin that does/helps with this (I don't like to have my template "depend" on a plugin)

share|improve this question

Try this - I've not implemented it fully, but I have tested it and it seems to work. Place it in your functions.php and call <?php list_child_pages(); ?> in your template or use the shortcode [childpages] in your editor.

// List Child pages of a parent. 
function list_child_pages() {

global $post;

if ( is_page() && $post->post_parent )
    $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
    $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );

if ( $childpages ) { ?>
        <ul class="side-nav">
            <?php echo $string = $childpages; ?>

return $string;

// Add Shortcode for additional support, not just in the theme template
add_shortcode('childpages', 'list_child_pages');

share|improve this answer

Your Answer


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.