WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp list_pages function: show children of current parent only (6 posts)

  1. lysergic73
    Member
    Posted 4 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 4 years ago #

  3. lysergic73
    Member
    Posted 4 years ago #

    @Esmi: It's not so easy mate!
    None of the examples works like I need :(

  4. lysergic73
    Member
    Posted 4 years ago #

    again... anybody can help?

  5. lysergic73
    Member
    Posted 4 years ago #

    found the solution: Hierarchical Pages widget

  6. quartermane
    Member
    Posted 4 years ago #

    Thank your for posting that link. This is the solution I've been looking for all week!

    Did you figure out a way to style the menu?

Topic Closed

This topic has been closed to new replies.

About this Topic