【问题标题】:Display Wordpress child pages on parent page在父页面上显示 Wordpress 子页面
【发布时间】:2015-01-17 12:38:54
【问题描述】:

我需要在 Wordpress 的父页面上显示子页面的内容(不是帖子)。这有效,显示子页面的标题,但我无法获得要显示的内容。 (最后两行)

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
}

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    正确的变量是post_content

    试试echo $tc-&gt;post_content;

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

    【讨论】:

    • 您的修复对我有用,谢谢,但是您知道当在带有 post_content 的父页面上显示时,我如何获得在子页面中呈现的简码吗?我在子页面上有一个图库,但现在它在父页面上以纯文本形式输出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    相关资源
    最近更新 更多