• Resolved InHouse

    (@inhouse)


    Hello, I’m having trouble trying to list child pages of the current page. I have read the Codex page about 30 times and tried every variation I saw. I can successfully list the child pages of a current page but I cannot get the offset to work properly. I on;y want to show lower level pages. Please see my example as this sounds confusing even to me. I’ve tried each of the examples below with limited success. All 3 are currently on my page template so you can see how they are all functioning. Can someone help me modify the list pages code to work properly? I am only partially understanding how this works. Thanks.

    Top Level

    Lowest Level

    Current code in page template

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter InHouse

    (@inhouse)

    Basically, I know I can accomplish this with 2 separate page templates but I’d like to make it easier for the website admins. If they create a new page, they shouldn’t have to worry about which page template to use. I am looking for a solution that uses 1 page template. I just can’t find a workable solution. Any suggestions?

    Thread Starter InHouse

    (@inhouse)

    Well, I figured I would post the code I ended up using. Not sure if it’s the best way to do this but it is working exactly as I want it to so I guess I win. When you are on a page in the sidebar (secondary) nav, there is a list of child pages to select from. When you are on one of those child pages, the same child pages remain. I’ve used exclude to ensure the top level pages are not displayed. You would need to alter this of course to fit your site structure.

    <div class="child-nav">
    <?php
    $output = wp_list_pages('echo=0&exclude=5,8,11,14,17&depth=1&title_li=' );
    if (is_page( )) {
      $page = $post->ID;
      if ($post->post_parent) {
        $page = $post->post_parent;
      }
      $children=wp_list_pages( 'echo=0&exclude=5,8,11,14,17&child_of=' . $page . '&title_li=' );
      if ($children) {
        $output = wp_list_pages ('echo=0&exclude=5,8,11,14,17&child_of=' . $page . '&title_li=');
      }
    }
    echo $output;
    ?>
      		</div><!--end child-nav-->
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List Child Pages Offset Help’ is closed to new replies.