WordPress.org

Ready to get started?Download WordPress

Forums

Listing Other Children of Parent Page (6 posts)

  1. misterpatrick67
    Member
    Posted 3 years ago #

    Hello all,

    trying to get my head around this one. I'm sure it's a simple solution. I am using the following script to get generate my navigation. Works fine and lists all the children of the parent, but as soon as I navigate to one of the children it obviously doesn't work.

    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) {
    ?>
    <?php echo $children; ?>
    <?php } ?>
  2. donnytree
    Member
    Posted 3 years ago #

    So is this in your side navigation? What happens when you go to a child page? The navigation all disappears or it only shows it's own children?

    For my side navigation, I first test for the parent page and then call wp_list_pages, e.g.,

    $parent = $post->post_parent;
    $parentTitle = get_the_title($parent);
    if ($parentTitle == 'Library') {
    wp_list_pages("title_li=&child_of=$parent&depth=0" ); }

    This lists the pages and subpages. I hope this helps.

  3. misterpatrick67
    Member
    Posted 3 years ago #

    Thanks, your solution put me on the right track. It wasn't showing the other children/subpages when browsing one of the children. Here's the code that works:

    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0');
    if ($children) { ?> <?php echo $children; ?>
    <?php } ?>
  4. donnytree
    Member
    Posted 3 years ago #

    Great! And just to clean it up a little:

    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0');
    if ($children) {
        echo $children;
    }
    ?>
  5. misterpatrick67
    Member
    Posted 3 years ago #

    Thanks! Now here's another question I am trying to wrap my head around. I have some static navigation that I using this on the

  6. 's to determine which one is current and styling it as current:

    <?php if (is_page('pagename')) { echo "current"; } ?>

    When I am using a wp_list_pages I am not sure how I can append something like this to the list item ($children). Also, with the above bit of code, I also need it to determine is it both is_page or is_parent so that the parent page is also active. So basically, when you are on a subpage you see both the parent and the particular child pag you're on styled as "current".

  • donnytree
    Member
    Posted 3 years ago #

    For that I use this plugin: Classy wp_list_pages

    And then have this code in my css:

    li.current_page_item a, li.current_page_parent a {  }
    li.current_page_item ul.children a {}
  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags