How to show all Child Pages in Wordpress
One thing I have learned today is how to get child pages of a particular page. A few internet searches and keyboard smashing I have finally gotten the answer.
To gett the a post pages, we needed to use a new WP_Query class object and pass the appropriate results.
In the following WP_Query, 'post_parent' and 'post-_type were the most important things to remember.
post_parentis used for querying. We will need the
post idof the current page we are on. Luckily for us, the post id of the current page was easy to get,
post_typeis used for us to tell WP_Query that we only want pages or posts.
<?php $query = new WP_Query(array('showposts' => 20, 'post_parent' => $post->ID, 'post_type' => 'page')); while ($query->have_posts()): $query->the_post(); ?> <?php the_title(); ?> <?php endwhile; wp_reset_query(); ?>
Wordpress, here I come!
Categories: How To