Jigowatt

WordPress – List subpages including their post tumbnails

Posted by Jay on Thursday, January 7th, 2010 at 1:15 pm

We’re building a WordPress web site for a local hairdressers which is obviously quite gallery intensive. To tackle this issue using WordPress we’ve used the Cleaner Gallery plugin which is great, but our issue was on the galleries parent page where we had some brief description text followed by a simple text list of the galleries (sub pages).

Displaying sub pages is easy enough but we wanted to incorporate WordPress 2.9’s post thumbnail function to display the sub page title, and next to it the post thumbnail.

The first step is to make the theme “post thumbnail compatible” by adding the following to the themes functions.php file:

1
add_theme_support( 'post-thumbnails' );

With post thumbnail support enabled we added a thumbnail to each of the gallery pages. Then, on the parent page template we used to following code to achieve the desired effect:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<ul class="subpages">
<span style="display:none;"><?php the_ID(); ?></span>
<?php $parent = $post->ID; ?>
<?php
query_posts('posts_per_page=15&post_type=page&post_parent='.$parent);
 while (have_posts()) : the_post();
?>

<?php $image_thumb = get_post_meta($post->ID, 'image-thumb', true); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?>
<h4><?php the_title(); ?></h4></a></li>

<?php endwhile; ?>
</ul>

This outputs all of the child pages in an unordered list, including the post thumbnail (if one is present) and the page title, all as a link to the actual page itself. Enjoy!

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Design Float
  • email
  • StumbleUpon
  • Twitthis

Related posts:

Leave a Reply