WordPress.org

Forums

[resolved] Sidebar Children (3 posts)

  1. cpashia
    Member
    Posted 8 years ago #

    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.

  2. moshu
    Member
    Posted 8 years ago #

    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.

  3. cpashia
    Member
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic