WP_LIST_PAGES 使用 WP_QUERY 的自定义输出
WP_LIST_PAGES custom output using WP_QUERY
我需要显示父页面的所有子项和孙项,但我想要自定义输出而不是 wp_list_pages();
给出的标准输出
<?php
wp_list_pages( array(
'title_li' => '',
'child_of' => $post->ID
));
?>
我成功地显示了子页面,但是没有孙子使用这个:
<?php
$args = array(
'post_type' => 'page',
'post_parent' => $post->ID,
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" rel="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="table">
<div class="table-cell">
<span></span>
<h3><?php the_title(); ?></h3>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
关于如何扩展此代码以像原始 wp_list_pages() 一样在子页面下显示孙子的任何建议?
谢谢!
我设法找到了扩展 wp_list_pages();
的好方法
<?php
wp_list_pages( array(
'title_li' => '',
'child_of' => $post->ID,
'link_before' => '<span></span><h3>',
'link_after' => '</h3>'
));
?>
这不是我想要的,我想自定义列表并添加一些额外的东西,但这对我的需要来说效果很好。
我需要显示父页面的所有子项和孙项,但我想要自定义输出而不是 wp_list_pages();
给出的标准输出<?php
wp_list_pages( array(
'title_li' => '',
'child_of' => $post->ID
));
?>
我成功地显示了子页面,但是没有孙子使用这个:
<?php
$args = array(
'post_type' => 'page',
'post_parent' => $post->ID,
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" rel="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="table">
<div class="table-cell">
<span></span>
<h3><?php the_title(); ?></h3>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
关于如何扩展此代码以像原始 wp_list_pages() 一样在子页面下显示孙子的任何建议?
谢谢!
我设法找到了扩展 wp_list_pages();
的好方法<?php
wp_list_pages( array(
'title_li' => '',
'child_of' => $post->ID,
'link_before' => '<span></span><h3>',
'link_after' => '</h3>'
));
?>
这不是我想要的,我想自定义列表并添加一些额外的东西,但这对我的需要来说效果很好。