Looping Through All Children of a Page

This query illustrates how to combine several arguments. Here, you want to list pages instead of posts, so use post_type to grab those. You don't want all the pages, just the children of page ID 1364, so use the post_parent attribute. Then you need to sort them by menu_order, an attribute unique to pages, and list them in ascending order, rather than the default descending. Finally, to make sure you get all the children of 1364 without bumping into the per-page limit set in the Reading Settings screen, set posts_per_page to -1. Setting posts_per_page to a negative value removes the per-page limit, thus showing all the posts at once.

Listing 7-4. A home page template file with a Loop showing children of page ID 1364

Template Name: Home Page

0 0

Post a comment