ttmt
ttmt

Reputation: 4984

Wordpress List all pages and children in separate ul

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 code below 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 same 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.

Upvotes: 0

Views: 631

Answers (1)

ovi_mihai
ovi_mihai

Reputation: 91

wp_list_pages('title_li=&depth=0&child_of'.$page->ID.'');

you'r missing the "=" after "child_of"

wp_list_pages('title_li=&depth=0&child_of='.$page->ID.'');

The nicer way to do this is to create a custom walker, but this is more complicated http://codex.wordpress.org/Function_Reference/Walker_Class

Upvotes: 2

Related Questions