我正在尝试遍历所有页面,这些页面是101的id的伟大孙子,但我不能让它工作。对问题可能是什么建议?
$args = array(
'post_type' => 'page',
'page_id' => $greatGreatGrandChild-of-101, ?
'posts_per_page' => -1
);
答案 0 :(得分:0)
好的,我最终这样做了。这列出了所有伟大的曾孙子或id为101的页面。
<ul>
<?php
$postid = 101;
$args = array(
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => 'rand',
'posts_per_page' => -1,
'post_parent' => $postid
);
$child_level = get_posts($args);
if($child_level) :
foreach($child_level as $child_page) :
$chgs = array(
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => 'rand',
'posts_per_page' => -1,
'post_parent' => $child_page->ID
);
$grandchild_level = get_posts( $chgs );
if($grandchild_level) :
foreach($grandchild_level as $grandchild_level) :
$grgs = array(
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => 'rand',
'posts_per_page' => -1,
'post_parent' => $grandchild_level->ID
);
$greatgrandchild_level = get_posts( $grgs );
if($greatgrandchild_level) :
foreach ($greatgrandchild_level as $greatgrandchild_level) :
$ggrgs = array(
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => 'rand',
'posts_per_page' => -1,
'post_parent' => $greatgrandchild_level->ID
);
$greatgreatgrandchild_level = get_posts( $ggrgs );
$my_query = new WP_Query($ggrgs);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile;
}
wp_reset_query();
endforeach;
endif;
endforeach;
endif;
endforeach;
endif;
?>
</ul>