How to show all Child Pages in Wordpress
I have an urge to learn wordpress, the world's most used blogging platform. With this I have been migrating my resources from FrogCMS to 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 thepost idof the current page we are on. Luckily for us, the post id of the current page was easy to get,$post->IDpost_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
Tags: wordpress
No Comments