子ページの投稿内容を表示する : WordPress

Pocket

子ページの投稿内容を表示するコード。

<?php if(have_posts()):while(have_posts()):the_post() ?>
    <h1><?php the_title(); ?></h1>
    // 子ページ開始
    <?php $lastposts = get_posts('post_type=page&post_parent=' . $post->ID); ?>
    <?php foreach($lastposts as $post) : setup_postdata($post); ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <?php the_content(); ?>
    <?php endforeach; ?>
    <?php wp_reset_postdata(); ?>
    // 子ページ終了
    <?php the_content(); ?>
<?php endwhile;endif; ?>

post_typeのデフォルトはpostであることを忘れていて手間取った。

コメント


  1. This is what we need – an insight to make eevryone think

    コメント by Nook — 2011-12-15 @ 5:58 AM

コメントの投稿

改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。