Help us understand the problem. What is going on with this article?

親ページに子ページ一覧を表示させる

More than 5 years have passed since last update.

親ページに子ページ一覧を表示させる方法

wordpressで固定ページを階層化させることはよくあるけど、
親ページには子ページの一覧だけ表示させれば良いということもよくある。

子ページを追加する度に親ページに追加していくのは面倒なので自動で追加されるようなコードを見つけたので備忘録として残します。

<?php
    $child_posts = query_posts( 'numberposts=-1&order=ASC&orderby=post_title&post_type=page&post_parent=' . $post->ID );
    if ( $child_posts ) {
        foreach ( $child_posts as $child ) {
            $c_title = apply_filters( 'the_title', $child->post_title );
            $c_permalink = apply_filters( 'the_permalink', get_permalink( $child->ID ) );
            $c_image_id = get_post_thumbnail_id($child->ID);
            $c_image_url = wp_get_attachment_image_src($c_image_id, '', true);
?>
    <div class="child-pages">
        <a href="<?php echo $c_permalink; ?>">
            <img src="<?php echo $c_image_url[0]; ?>" />
            <p><?php echo $c_title; ?></p>
        </a>
    </div><!-- .child-pages -->
<?php
        }
    }
?>
shimayu
プログラム初心者ですが一生懸命勉強しています。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした