0

我整个周末都在尝试这样做,现在我正在转圈。

我想在单独的 ul 中列出所有页面及其子项

页面设置是这样的

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

我想这样输出

    <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>

下面的代码将为我提供单独 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;
                    ?>  
          </li>
        </ul>
        <?php
      }

    ?>

我现在正在尝试将子页面添加到同一个 ul

我在想这样的事情,但这给了我每个 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
      }

    ?>        

有没有办法说这个页面的所有孩子。

任何帮助将不胜感激。

4

1 回答 1

2

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

您在“child_of”之后缺少“=”

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

更好的方法是创建一个自定义walker,但这更复杂 http://codex.wordpress.org/Function_Reference/Walker_Class

于 2013-02-24T21:40:26.490 回答