Recently, I needed to list all subpages of a parent page.  I also needed to display custom fields below each subpage. And, on top of that, the list needed to be 2 columns.

I found a solution for simply listing the pages in 2 columns, but it did not suggest how to modify the code to include custom fields.

So, thanks to our coding hero Mark Kaplun who supplied the below code, although he admits it’s a “dirty hack”. The sort_column is so that MyPageOrder would work properly for this listing.

<?php
$args = array(
‘post_type’ => ‘page’,
‘numberposts’ => 40,
‘sort_column’ => ‘menu_order’,
‘child_of’ => 84 // any parent
);
$attachments = get_pages($args);
//print_r(“attachements:” . $attachements);
echo ‘<div style=”float: left; margin: 0 10px 0 0;”>’;
?>

<?php
for ($i =0; $i<count($attachments)/2; $i++) {
$post = $attachments[$i];
//    foreach ($attachments as $post)  { ?>

<a href=”<?php echo get_permalink($post->ID) ?>” rel=”bookmark”><?php echo $post->post_title; ?></a>
<?php if(get_post_meta($post->ID, “NameofCustomField”, true)) { ?>
<?php
echo get_post_meta($post->ID, “NameofCustomField”, true);
}
?>
<?php } ?>
</div>
<?php
echo ‘<div style=”float: left; margin: 0 10px 0 0;”>’;
for (; $i<count($attachments); $i++) {
$post = $attachments[$i];
//    foreach ($attachments as $post)  { ?>

<a href=”<?php echo get_permalink($post->ID) ?>” rel=”bookmark”><?php echo $post->post_title; ?></a>
<?php if(get_post_meta($post->ID, “PracticeArea”, true)) { ?>
<?php
echo get_post_meta($post->ID, “PracticeArea”, true);
}
?>
<?php } ?>
</div>