Create a WordPress Page Template to Display Subpage Content

Create a WordPress Page Template to Display Subpage Content

Posted by Rainey

WordPress page templates are pretty powerful and can be used to change the layout of your pages in a variety of ways. This is great when handling content that fits into WordPress’ page construct or even a WordPress page with extra meta fields added.  But, sometimes a longer form page is desired that also has more intentional layout. To accomplish this we could build out the layout in HTML and paste it into the page. But then the client will probably muck it up and the page will look like rubbish.

One way to address this is to create a subpage  WordPress page template that outputs all subpage content into the current page. Here is how that might look:

<?php

$current_page_id = $post->ID;

query_posts(array('showposts' => 20, 'post_parent' => $post->ID, 'post_type' => 'page')); 
while (have_posts()) { the_post(); ?>
   <h1><?php the_title(); ?></h1>
   <?php the_content(); 
} ?>

Now we have a basic setup that we can layout in any way we please.

Like what you are reading? Subscribe to receive monthly tips & updates!

A Monthly Roundup of Articles and a Sweet Deal

Get the latest tips, tricks, tutorials and freebies in your inbox once a monthly.

Join our growing community of front-end web developers and designers. We are constantly publishing new industry tips, tricks and tutorials to help you take your game to the next level. We are also going to include a freebie or deal on something cool each month. Enter your email below and you will only receive this email once a month, nothing else.

Subscribe to our mailing list

* indicates required


    Today in Web Design - PHP, Tutorials, WordPress
    Tagged | , ,