我有这个代码在wordpress主题中运行子页面导航。
这在其他地方完美运作。这几乎与get_page_children的codex页面保持不变。我检查了$post->ID, $subpage_query
和$all_pages
,一切都很好。它只是拒绝填充$page
变量,没有明显的原因。
<div class="sub-pages">
<?php
$subpage_query = new WP_Query();
$all_pages = $subpage_query->query(array('post_type' => 'page', 'orderby' => 'date'));
$subpages = get_page_children( $post->ID, $all_pages );
$pa = 0;
foreach ($subpages as $k => $page) {
if ($pa > 3) {
break;
}?>
<div class="sub-page">
<a href="<?php echo get_permalink($page -> ID); ?>">
<div class="overload"><?php echo get_the_post_thumbnail( $page -> ID, 'medium'); ?></div>
<p><?php echo $page -> post_title; ?></p>
</a>
</div>
<?php $pa++; } ?>
</div>
答案 0 :(得分:1)
尝试
$all_pages = $subpage_query->query(array('post_type' => 'page', 'orderby' => 'date', 'posts_per_page' => -1)));