tobypitman.com

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

I thought I’d share this with anybody who’s interested. I’m currently developing a site based in Wordpress that has a lot of nested child pages.

I’ve used the new ‘Post Thumbnail’ feature in 2.9 to link to the child pages from the ‘Parent’ page using the Post Thumbnail as an image link. The reason for this is the client no longer has to faff about with customs fields, which are confusing to non-web savvy users.

This might be useful for people building portfolio sites for artists.

The code I’d previously been dabbling with pulled in a custom field called ‘Imagelink’ from all the child pages associated with the parent page providing an image link to that child page.

The code below uses ‘get_the_post_thumbnail()’ so all the client has to do is upload an image using the new ‘Post Thumbnail’ feature in every new page as the link image.

ms-1

Insert it into a page template in wordpress called ‘childLinks’ or something like that.

<?php $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID);
 $count = 0;
foreach($pages as $page) { $content = $page->post_content;?>

<div class="childPageLink">
       
<a href="<?php echo get_page_link($page->ID) ?>"><?php echo get_the_post_thumbnail($page->ID, 'full'); ?></a>      
               
</div>
       
<?php } ?>

Pretty handy and more CMS like.

Posted on Tuesday, December 22nd, 2009 at 8:56 pm.

Filed under Web Design.

2 Responses to “Link to ‘child pages’ in Wordpress with ‘the_post_thumbnail’”

  1. Thanks for sharing! – This was such a great help to me.

  2. Thanks! This sure helped me with a WordPress shopping cart for categorizing products.

Don't be shy, leave a comment