您的代码有太多错误,启动WP\\U查询时没有\'sort_column\'
, 或\'depth\'
参数。使用$do_not_duplicate = $post->ID;
什么都不做,还有其他一些事情。
您需要的是获取子项(仅ID,无需获取post对象,因为您不使用除标题和premlink之外的任何字段),对它们进行循环,并为每个子项获取子项(意味着主页孙子)并对其进行循环。
类似这样:
<?php
//store page
$temp = $post;
//get children
$children = get_posts(array(
\'orderby\' => \'menu_order\',
\'post_per_page\' => 30,
\'post_parent\' => $post->ID,
\'post_type\' => \'page\',
\'fields\' => \'ids\')
);
//children loop
foreach ($children as $child) {
$do_not_duplicate[] = $child;
?>
<div id="child">
<h2 class="clear"><a href="<?php echo get_permalink($child); ?>" ><?php echo get_the_title($child); ?></a></h2>
</div> <?php
//get grandchildren
$grandchildren = get_posts(array(
\'orderby\' => \'menu_order\',
\'post_per_page\' => 3,
\'post_parent\' => $child,
\'post_type\' => \'page\',
\'fields\' => \'ids\')
);
$count = 0;
//grandchildren loop
foreach($grandchildren as $granchild){
setup_postdata($granchild);
$count++;
if ($count == 0){ ?>
<div id="top">
<div class="first"> </div>
<h3 class="clear"><a href="<?php the_permalink($granchild); ?>" ><?php the_title($granchild); ?></a></h3>
<?php echo get_the_post_thumbnail($granchild->ID, \'thumbnail\'); ?>
<p class="clear"><?php the_content(\'read more...\'); ?></p>
</div> <?php
}elseif ($count == 1){ ?>
<div class="middle">
<h3><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3>
<p class="clear"><?php the_content(\'read more...\'); ?></p>
</div> <?php
}else { ?>
<div class="last">
<h3><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3>
<p class="clear"><?php the_content(\'read more...\'); ?></p>
</div><?php
}
}
}
//restore page
$post = $temp;