在父页面上显示Wordpress子页面

时间:2014-11-19 20:22:03

标签: php wordpress

我需要在Wordpress(不是帖子)的父页面上显示子页面的内容。这工作,显示子页面的标题,但我无法显示内容。 (最后2行)

global $post;
$args = array( 'numberposts' => 1, 'category_name' => 'foundation','post__in' => get_option( 'sticky_posts' ) );

$the_query = new WP_Query( $args );

while ($the_query -> have_posts()) {
    $the_query->the_post();
?>

<article class="lead">
    <h1><?php the_title(); ?></h1>
    <section>
        <?php the_content(); ?>
    </section>
</article>

<?php
}

$newQuery = new WP_Query();
$all_pages  = $newQuery->query(array('post_type' => 'page'));

$foundation = get_page_by_title('Foundation');
$foundation_children = get_page_children($foundation->ID, $all_pages);

query_posts('pagename=foundation');

while(have_posts()) {
    the_post();
    the_title();
    the_content();
}

foreach($foundation_children as $tc) {
    echo $tc->post_title; // this works
    echo $tc->the_content; // this doesn't
}

1 个答案:

答案 0 :(得分:0)

正确的变量是post_content

尝试echo $tc->post_content;

参考:http://codex.wordpress.org/Class_Reference/WP_Post