Support » Themes and Templates » wp_list_pages issue

  • 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:

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

    <?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");?>
    <?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!


Viewing 6 replies - 1 through 6 (of 6 total)
  • would adding something like this make it work?

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

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

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

    Thanks for the response tho!

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

    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");?>
    <?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"); ?>
    <?php }

    You can see it in action at: (see the test page)

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

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


    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. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_list_pages issue’ is closed to new replies.