15
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-03-28

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

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
		}
	}
?>
15
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?