Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been trying to do this all weekend, I'm going round in circles now.

I want to list all pages and their children in separate ul's

The page setup is like this

    HOME        ABOUT         CONTACT
                Who we are    Where we are 
                What we do    How to find us
                How we do it  

I want to output it like this

    <ul>
      <li>Home</li>
    </ul>

    <ul>
      <li>About</li>
      <li>Who we are</li>
      <li>What we do</li>
      <li>How we do it</li>
    </ul>

    <ul>
      <li>Contact</li>
      <li>Where we are</li>
      <li>How to find us</li>
    </ul>

This will give me the top pages in separate ul's

    <?php
      $args = array(
        'sort_column' => 'menu_order',
        'parent' => 0,
      );
      $pages = get_pages($args);
      foreach($pages as $page){
        ?>
        <ul>
          <li>
            <?php 
                        echo $page->post_title;
                    ?>  
          </li>
        </ul>
        <?php
      }

    ?>

I'm now trying to add the child pages to the ul

I'm thinking something like this but this gives me all the pages in each ul

    <?php
      $args = array(
        'sort_column' => 'menu_order',
        'parent' => 0,
      );
      $pages = get_pages($args);
      foreach($pages as $page){
        ?>
        <ul>
          <li>
            <?php 
                        echo $page->post_title;
                        wp_list_pages('title_li=&depth=0&child_of'.$page->ID.'');
                    ?>  
          </li>
        </ul>
        <?php
      }

    ?>        

Is there a way to say all children of this page.

Any help would be greatly appreciated.

share|improve this question
add comment

1 Answer

your code is missing the = after child_of

<?php
$args = array(
    'sort_column' => 'menu_order',
    'parent' => 0,
    );
$pages = get_pages($args);
foreach($pages as $page){
    ?>
    <ul>
        <li>
        <?php 
        echo '<a href="' . get_permalink( $page->ID ) . '">' . $page->post_title . '</a>';
        ?>  
        </li>
        <?php  
        wp_list_pages('title_li=&depth=0&child_of='.$page->ID.'');
        ?>  
    </ul>
    <?php
    }
?> 

if you want to make sure to only show one level of child pages, consider to set the 'depth' parameter to 1

share|improve this answer
    
Thanks Michael, best part of a day messing with this and I was missing a "=" –  user668499 Feb 25 '13 at 9:15
    
Might have spoken too soon. The first echo echo $page->post_title; just gives me text of the page but I need that to be a link as well –  user668499 Feb 25 '13 at 9:27
    
edited to show parent pages as link. this is the edited line: echo '<a href="' . get_permalink( $page->ID ) . '">' . $page->post_title . '</a>'; –  Michael Feb 25 '13 at 11:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.