treehouse : what would you like to learn today?
Web Design Web Development iOS Development

wp_list_pages struggles

  • Hi,

    I have been struggling with this for way too long and I hope someone can help me or point me in the right direction.

    I have a PAGE page that is a parent page and some of the child pages of that parent page have child pages as well, some don't.

    Lets call the top parent page, "A"
    "A" has child pages "B", "C", "D"
    "C" has child pages "E", "F" and "G"

    on "A" I would like to list pages "B", "C" and "D"
    on "C" I would like to list pages "E", "F" and "G"
    on "E", "F" and "G" I would like to list pages "E", F", and "G"

    I tried every example on the codex, and mostly I get a list of every page on my site, not just this post parent and children.

    Anyone have any ideas?

    For example:

    from the codex - The following example will generate a list only if there are child (Pages that designate the current page as a Parent) for the current Page:

    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>


    But this displays every page on my site. :-(
  • Getting closer but not quite there yet.

    Here is what I have now in my child functions.php - I use Thematic

    // Add training articles menu list
    function training_articles_menu() {
    global $post;
    if (is_page('training-articles') || ($post->post_parent=="205")) { ?>

    <?php
    $children = wp_list_pages('depth=1&title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>

    <div id="training-menu" class="aside main-aside">
    <ul>
    <h3>Training Articles by Chris Krowchuk</h3>
    <ul>
    <?php echo $children; ?>
    </ul>
    </ul>
    </div><!-- end training menu -->

    <?php } ?>

    <?php }else{ ?>
    <?php }
    }
    add_action('thematic_belowpost','training_articles_menu');


    This displays the list of the child pages when on the parent and it displays a list of child pages when on a child pages (if there are any).

    The only thing I am missing that I would like is the list of pages that are grandchildren when on a grandchild page, if they exist.

    Does that make sense? It confuses the heck out of me!

    So, I have a Parent page, and under that page I have child pages. Some of these child pages also have children, some do not.

    I can get a list of child pages when on the parent no problem.
    I can get a list of grandchild pages when I am on a child page that has children
    I can't get a list of grandchild pages when I am on a grandchild page in the same hierarchy. This is what I would like to add somehow?

    Right now I have the grandchild list hard-coded into the grandchild pages and that is fine, but I would like it dynamic obviously.

    Example: www.krowchukdressage.com/training-articles/ is the main parent page

    Any wp_list_pages() experts here?