Link to ‘child pages’ in WordPress with ‘the_post_thumbnail’

WordPress 2.9 has been released and comes packed with some awesome new features. One of the new feature that I am loving as I have been longing for it, is the post thumbnail. This is a new feature in WordPress that allows you to upload an image to a post that you are creating and attaches to the post as its thumbnail. No longer do you have to use custom fields if all you want is a image for you posts.

It can be used for both posts and pages so I may use both post or page interchangeable throughout this post. I’ve recently used the new ‘Post Thumbnail’ feature in 2.9 to link child pages from a ‘Parent’ page using the Post Thumbnail as an image link.

Wordpress Post Thumbnail

The code below is an example of how to use the ‘get_the_post_thumbnail()’ to list the current page children with its content and a title.

<?php
// get pages
$pages = get_pages("child_of=".$post->ID.'&sort_column=post_title&sort_order=desc&parent='.$post->ID);
// loop through pages pages to get page properties
foreach($pages as $page) {
?>
<div class="wp-caption alignleft">
// create an hyperlink from the get_page_link method and embed the image retrieved from get_the_post_thumbnail in it
<a href="<?php echo get_page_link($page->ID) ?><?php echo get_the_post_thumbnail($page->ID); ?>
// get the title and use it as the caption
<?= $page->post_title ?>
</div>
// get the content
<?php echo $page->post_content; ?>
<?php edit_post_link('Edit.', '', '', $page->ID); ?>
<?php } ?>