CodeIgniter, Kohana, Mootools, jQuery and CSS

How to show all Child Pages in Wordpress

Posted by teejay on January 22, 2012

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_parent is used for querying. We will need the post id of the current page we are on. Luckily for us, the post id of the current page was easy to get, $post->ID
  • post_type is used for us to tell WP_Query that we only want pages or posts.
      $query = new WP_Query(array('showposts' => 20, 'post_parent' =>  $post->ID, 'post_type' => 'page'));
      while ($query->have_posts()):
    <?php the_title(); ?>

Wordpress, here I come!

Categories: How To

Tags: wordpress

No Comments

Comments are not allowed