Cho độ tuổi của câu hỏi này tôi muốn cung cấp câu trả lời cập nhật cho bất kỳ ai tình cờ gặp nó.
Tôi khuyên bạn nên tránh query_posts. Đây là lựa chọn thay thế tôi thích:
$child_pages = new WP_Query(array(
'post_type' => 'page', // set the post type to page
'posts_per_page' => 10, // number of posts (pages) to show
'post_parent' => <ID of the parent page>, // enter the post ID of the parent page
'no_found_rows' => true, // no pagination necessary so improve efficiency of loop
));
if ($child_pages->have_posts()) : while ($child_pages->have_posts()) : $child_pages->the_post();
// Do whatever you want to do for every page. the_title(), the_permalink(), etc...
endwhile; endif;
wp_reset_postdata();
Một giải pháp thay thế khác là sử dụng bộ lọc pre_get_posts tuy nhiên điều này chỉ áp dụng trong trường hợp này nếu bạn cần sửa đổi vòng lặp chính. Ví dụ trên là tốt hơn khi được sử dụng như một vòng lặp thứ cấp.
Tiếp tục đọc: http://codex.wordpress.org/Class_Reference/WP_Query
Nguồn
2014-02-13 08:19:11
Nếu đó là trang con của trang hiện tại bạn có thể sử dụng 'get_the_ID()' nếu bạn gọi trước 'the_post() '. – jezmck