Support » Fixing WordPress » wp list_pages function: show children of current parent only

  • Resolved lysergic73

    (@lysergic73)


    Hi all, i used a lot the function wp_list_pages to display an usable navigation menu.

    Actually I use

    <?php if ( is_page() ) : ?>
    <?php $parentTitle = get_the_title($post->post_parent);?>
    <?php echo $parentTitle; ?>
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul class="subpages">
    <?php echo $children; ?>
    
    <?php } ?>
    <?php endif; ?>

    But it doesn’t works well with my last website because it shows all the subpages and not only the children of the current page.
    I try to explain better, the pages are:

    • parent 1
      • child 1 of parent 1
      • child 2 of parent 1
      • child 3 of parent 1
    • parent 2
      • child 1 of parent 2
      • child 2 of parent 2
      • child 3 of parent 2
    • parent 3
      • child 1 of parent 3
      • child 2 of parent 3
      • child 3 of parent 3

    I want to see always parents, but when I’m on child 2 of parent 3 I want to show only the children of parent 3
    like:

    • Parent 1
    • Parent 2
    • Parent 3
      • child 1 of parent 3
      • child 2 of parent 3
      • child 3 of parent 3

    Now if I’m on child 2 of parent 2 I see also all other children.

    Any help?

    Thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp list_pages function: show children of current parent only’ is closed to new replies.