WordPress.org

Ready to get started?Download WordPress

Forums

Display grandchild pages ONLY when onchild page (2 posts)

  1. rikardo85
    Member
    Posted 2 years ago #

    Hello,

    I currently have 3 levels of navigation.
    I can display the parent, child and grandchild pages fine using the code form the codex (below)

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    However I want the grandchild pages to display only when I have selected the child page (see below)

    Home
    About
    Service
    - child page 1
    - Grandchild page 1
    - Grandchild page 2
    - Grandchild page 3
    - child page 2
    - child page 3
    Portfolio
    Contact

    All child pages should still be on display when I am on a Grandchild page.

    Hope you can help.

  2. rikardo85
    Member
    Posted 2 years ago #

    Code I am currently using from the codex

    <?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) { ?>

      <?php echo $children; ?>

    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic