• I’m trying to list subpages and sub-subpages in sidebar, but for some reason wp-list-pages displays nothing.

    This is the code:

    $subpage_id = 212; // id number of a subpage, that has sub-subpages
    
    $subnavi = wp_list_pages('title_li=&child_of='.$subpage_id.'&echo=0');
    if ($subnavi) { ?>
    <ul>
    <li class="pagenav"><h2><a href="<?php echo get_permalink($subpage_id); ?>"><?php echo get_the_title($subpage_id); ?></a></h2>
    
    <ul> 
    
    <?php echo $subnavi; ?> 
    
    </ul>
    <li>
    </ul>
    
    <?php } ?>
    <?php endwhile; ?>

    Above code works fine when querying top pages, but won’t list anything when querying with sub-pages, that have sub-subpages.

    Is this a bug or feature? If it’s more of a feature how can I achieve the same result otherwise?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter daily

    (@daily)

    If i cannot use wp_list_pages, could somebody help me how to build correct query, to list all childpages of a certain subpage and their childs and so on.

    I’m trying to do the exact same thing…anyone have a solution?

    This is my code so far:

    <h1>
    <?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>
    </h1>
    
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
    if ($children) { ?>
    
    <?php echo $children; ?> 
    
    <?php } ?>

    Currently it shows the grandparent page as the title and subsequent parent pages underneath in the sidebar when on a grandparent or parent page that has no children. It then shows the parent page as the title and the child pages underneath when on a child page. This is great, except what I want it to do is when a parent page has children and you are on the parent page, I want the title to be the parent and the children to be underneath in the sidebar. I hope this makes sense.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP List Pages: Can’t list subpages’ is closed to new replies.