Support » Fixing WordPress » Sidebar Children

  • Resolved cpashia

    (@cpashia)


    Someone gave me a php script that shows all the child pages of whatever page the script was put in. It looks like this:

    <?php if(wp_list_pages(“child_of=”.$post->ID.”&echo=0″)) { ?>
    <div id=”childpagelist”>

      <?php wp_list_pages(“title_li=&child_of=”.$post->ID.”&sort_column=menu_order”);?>

    </div>
    <?php } ?>

    The problem I am having is that the sidebar is listing the child pages fine, but it is listing the child pages of the child pages, so it looks like this:

    Child 1
    Child 2
    Child of Child 2
    Child 3

    How do I make it list only the child pages of the parent page? I want it to look like this:

    Child 1
    Child 2
    Child 3

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Normally, the wp_list_pages tag has a “depth” parameter:
    http://codex.wordpress.org/Template_Tags/wp_list_pages
    According to your code above the parameters should work, so I’d try to play with that.

    Ah I see. I changed the code to this:

    <?php if(wp_list_pages(“child_of=”.$post->post_parent.”&echo=0″)) { ?>

      <?php wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&sort_column=menu_order&show_date=modified&date_format=$date_format&depth=1″);?>

    <?php } ?>

    It is working beautifully. Thank you very much, moshu.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sidebar Children’ is closed to new replies.