Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress使用get_pages()进行分层子页面显示_Wordpress_Tree - Fatal编程技术网

wordpress使用get_pages()进行分层子页面显示

wordpress使用get_pages()进行分层子页面显示,wordpress,tree,Wordpress,Tree,我想使用get_pages()而不是wp_List_pages()来显示层次结构中的页面。例如: parent child child1 但是,是否可以使用下面的代码使用wp_list_pages()显示 <?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");

我想使用get_pages()而不是wp_List_pages()来显示层次结构中的页面。例如:

parent
   child
      child1
但是,是否可以使用下面的代码使用wp_list_pages()显示

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

参数的子项取消激活get_pages()函数的层次结构


您应该像使用第一个代码一样使用wp_list_pages函数。

child_of parameter会停用get_pages()函数的层次结构

您应该像第一个代码一样使用wp_list_pages函数

 <?php 
        global $post;
         if($post->post_parent)

   $child_pages = get_pages( array( 'child_of' => $post->post_parent, 'sort_column' => 'post_date', 'sort_order' => 'desc','hierarchical' => 1 ) );
  else
    $child_pages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc','hierarchical' => 1 ) );
  if ( $child_pages) { ?>

  <?php }  



        if ( $child_pages ) :?>
        <ul>
          <?php
                    foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?><?php $child_title= get_field('sidebar_tittle',$pageChild->ID);?>
          <li> 
                 <?php  if($child_title):?>
                        <a href="<?php echo get_permalink($pageChild->ID); ?>"  title="<?php echo $pageChild->post_title; ?>"><?php echo $child_title; ?>
                        </a>
                        <?php  else:?>
                       <a href="<?php echo get_permalink($pageChild->ID); ?>"  title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?>
                        </a>
                        <?php  endif;?>  


                        <span class="border_div"></span></li>
          <?php endforeach;?>
        </ul>
        <?php endif; ?>