好吧,我想我已经破解了。下面的代码似乎运行良好。为了能够使用自定义的post类型,我在$args数组中添加了一个参数\'post_type\' => \'product\',
下面的可以吗?
<div id="sub-pages">
<?php
global $post;
$args = array(
\'post_type\' => \'product\',
\'child_of\' => get_top_ancestor_id(),
\'title_li\' => \'\'
);
$the_query = new WP_Query($args);
?>
<ul>
<?php wp_list_pages($args); ?>
</ul>
<?php wp_reset_postdata(); ?>
</div>
// Get top ancestor
function get_top_ancestor_id() {
global $post;
if ($post->post_parent) {
$ancestors = array_reverse(get_post_ancestors($post->ID));
return $ancestors[0];
}
return $post->ID;
}