Display Child Pages

Today I came across the need to display the children of a specific page on that specific page on their WordPress site. Originally, I was going to create a custom post type for these children, but I because there would only be two children, I felt that creating a custom post type would be a bit of an overkill. Furthermore, the client for which I was building the site would likely be a bit confused as to why these children pages had a separate area when they really weren’t that different from a standard page. Therefore, I felt it would be best to simply display the child pages for this particular parent page.

Provided you have the ID of the post for which you’d like to display the children, this is fairly easy to accomplish. Below is the formula I used (just placed in page.php):

<?php if(is_page(8)) { ?>
     <?php $pages = get_pages(array('child_of' => 8, 'sort_colum' => 'menu_order', 'sort_order' => 'DESC'));
     foreach((array)$pages as $page) {
          $id = $page->ID;
          $image = get_the_post_thumbnail($id, 'full');
          $link = get_post_permalink($id);
          $title = $page->post_title;
          $content = $page->post_excerpt;

          <div class="attorney">
               <div class="image">
                    <?php echo $image;?>
               </div><!--/image-->
               <div class="info">
                    <h3><a href="<?php echo $link;?>"><?php echo $title;?></a></h3>
                    <p><?php echo $content;?></p>          
               </div><!--/info-->
          </div><!--/attorney-->
     <?php }
}?>
cw-index-1-r2
goUSF-index-1
usfgm-index-1-r3
bgl-index-1
ucon-index-1-r1
adopt-index-2
skalet-index-1-r2
pcabral
th-index-1
rms-index-2
km-index-1-r1
peu-index-2-r3b
pdu-index-1-r2a
oph-index-1-r2
mmm-index-1
long-index-1-r1a
ernies-index-1
cooks-index-1-r2a
df-index-1-r1
vs-index-1
uni-index-1
pe-wedding-print
Screen shot 2013-10-25 at 3.38.39 PM
fred
cabral
dava
psa
errg
apex
pag
cwb
beginners
awakealive
ecom
ab