我想使用 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()
我设置hierarchical=1
但它不工作
在我下面的代码中,它以单个 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; ?>