WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_pages issue (7 posts)

  1. andyk
    Member
    Posted 7 years ago #

    Hi all,

    I'm currently working on a new theme which I plan to release soon. In the top of the page I have a menu which I plan to list all of the top level pages and then, once into one of the pages, list all of the subpages. I have that working fine using the followign code:


    <ul>
    <li><a href="index.php">Home</a></li>
    <?php wp_list_pages('sort_column=menu_order&title_li=&depth=1'); ?>
    </ul>

    <?php if(wp_list_pages("child_of=".$post->ID."&echo=0")) { ?>
    <ul id="submenu">
    <?php wp_list_pages("title_li=&child_of=".$post->ID."&sort_column=menu_order&depth=2");?>
    </ul>
    <?php }  ?>

    However... I have a problem. If I click on a 'parent page' followed by the 'child page' all of that childs 'sibling pages' (pages owned by the same parent) vanish from the menu. It would seem logical to me that they should stay visible, but I can't seem to get it working.

    Does anyone have any suggestions for how I could do this please?

    I really appreciate the help. Thanks!

    Andy

  2. Jayjerome
    Member
    Posted 7 years ago #

    would adding something like this make it work?

    <?php if ($sub_pages <> "" ){?>

    <ul><?php echo $sub_pages; ?></ul>

  3. andyk
    Member
    Posted 7 years ago #

    Hmmm what is $sub_pages supposed to contain? I can't seem to get it to print anything out...

    Thanks for the response tho!

  4. andyk
    Member
    Posted 7 years ago #

    Yay! I sussed it... just had to be a bit creative:

    <?php
    if($post->page_type != 'post') {
    if(wp_list_pages("child_of=".$post->ID."&echo=0")) { ?>
    <ul id="submenu">
    <?php wp_list_pages("title_li=&child_of=".$post->ID."&sort_column=menu_order&depth=2");?>
    </ul>
    <?php } elseif(wp_list_pages("child_of=".$post->post_parent."&echo=0") && $post->post_parent != 0) { ?>
    <ul id="submenu">
    <?php wp_list_pages("title_li=&child_of=".$post->post_parent."&sort_column=menu_order&depth=2"); ?>
    </ul>
    <?php }
    }
    ?>

    You can see it in action at: http://www.bomb.org.uk (see the test page)

  5. k364
    Member
    Posted 7 years ago #

    thanks for posting the code. it's exactly what i was looking for. -though i'll be adding a back button.

  6. Shelley Keith
    Member
    Posted 7 years ago #

    This is exactly what I was looking for, thanks for posting it.

  7. Stephane Daury (stephdau)
    Member
    Posted 7 years ago #

    @andyk:

    There's a small typo in your code:

    if($post->page_type != 'post') {

    should be:

    if($post->post_type != 'post') {

    Thanks for the code though. It helped me figure out my page nav. :)

Topic Closed

This topic has been closed to new replies.

About this Topic