一般的な記事の取得にはquery_posts()
は非推奨とされていますので
代わりにWP_Query
クラスやget_posts()
関数を使用してください。
###get_posts()
を使ったサンプルコード
PHP
1<?php
2 $parentId = get_the_ID();
3 $args = array(
4 'post_type' => 'page',
5 'posts_per_page' => -1,
6 'post_parent' => $parentId,
7 'orderby' => 'menu_order',
8 'order' => 'ASC'
9 );
10 $posts = get_posts($args);
11 if ($posts) :
12 foreach ($posts as $post) :
13?>
14// ここに記事のHTML
15<?php
16 endforeach;
17 endif;
18?>
注 1: この関数はプラグインまたはテーマの中で使われることを想定されていません。後ほど出てくる説明にあるように、メインクエリーを変更するにはパフォーマンス面でも優れたより良いオプションが存在します。
テンプレートタグ/query posts
https://wpdocs.osdn.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/query_posts
テンプレートタグ/get posts
https://wpdocs.osdn.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/get_posts