wordpress use get_pages() for hierachical child pages display

I want to use get_pages() instead of wp_List_pages() for pages to display in hierarchy. For example:

parent
   child
      child1

However is it possible to display with wp_list_pages() using below code?

Read More
 <?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 } ?>

in get_pages() i set hierarchical=1 but its not working

in my below code it display them in single li

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

Related posts

Leave a Reply

1 comment