A picture is worth a thousand words – or so they say. This is certainly true for most website design and definitely the case for the fine artist – Heather Jane Wallace – who’s site we’ve developed. One thing that we want on the website is link to the pages that showcase her current collection but use the art to drive the interest, not the wordy links. So this is how we did it:
1. Add a function to the theme to call a thumbnail image from each post:
<?php
// Displays post image for the sidebar.
// Sizes can be; thumbnail, medium, full)
function side_th_image($postid=0, $size='thumbnail', $attributes='') {
if ($postid<1) $postid = get_the_ID();
if ($images = get_children(array(
'post_parent' => $postid,
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
foreach($images as $image) {
$attachment=wp_get_attachment_image_src($image->ID, $size);
?><?php echo $attachment[0]; ?><?php
}
}
?>
2. Now we need to call in these thumbnails to the sidebar. This will most likely be outside of the Wordpress loop. In this case we are using this to link to the post.
<ul>
<?php global $post;
$myposts = get_posts('category=1&numberposts=5&orderby=rand');
foreach($myposts as $post) : ?>
<li><img src="<?php side_th_image($post->ID); ?>" title="<?php the_title(); "></li>
<?php endforeach; ?>
</ul>
And that’s it. Easy peasey. Of course make sure that you’ve got styles to cover this (the thumbnails don’t look good with a bullet point infront of them!). And even better this can be reused for a category page. NB you don’t need $post->ID inside the brackets if this is appearing inside the loop.
Why not visit her site to see this in action, and while your there take a look at her provoking pieces! www.heatherjanewallace.com
