我在我的主题中使用以下代码。代码向我显示了页面176的子页面的标题,缩略图和链接。我希望它不仅显示子页面而且还显示来自176的内容。也许使用get_pages或wp_list_pages更好,但是wp_query的解决方案会很好。谢谢你的帮助。
function sd_recent() {
global $post;
$this_post = $post->ID;
// args
$args = array(
'post_type' => 'page',
'post_parent' => 176
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<ul class="recent-links">
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li <?php if( $this_post == $post->ID ) { echo ' class="current-recent-links"'; } ?>>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('full'); ?>
<span class="recent-links-title"><?php the_title(); ?></span>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_postdata();
}
答案 0 :(得分:0)
假设您希望父内容在循环外出现一次,您可以这样做......
global $post;
if ($post->post_parent) {
$parent = get_page($post->post_parent);
echo apply_filters('the_content', $parent->post_content);
}
如果您希望每次在循环中出现它,您可以将父内容分配给var并在循环中回显它。