Select Page

This code will allow you to automatically show child pages including custom fields in this case one called ‘desc’

You will need to add this code to your template file for example page.php


  <?php
        $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>
 		<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
  			<div class="child-thumb" onclick="location.href='<?php echo $pageChild->post_title; ?>';" style="cursor: pointer;">
			<?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
            <a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>">
			<?php echo $pageChild->post_title; ?></a>
		    <?php
                $customFields = get_post_custom($pageChild->ID);
                echo '<p class="desc">' . $customFields['desc'][0] . '</p>';
            ?>
            </div>
         <?php endforeach; endif;
         ?>