Hello everyone,
I have pieced together two small functions. One that grabs an image from an attached post, and second which creates a list of featured posts using a category.
I thought it would be no problem to simply reference my image function with in my feature function, and list a set of featured stories with their image, with the image and text as a hyperlink.
However, the image seems to pop out of the echo element.
Here are my functions:
//post image function
function postimage($size=thumbnail) {
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo $attachmentimage;
}
} else {
echo '<!-- No image -->';
}
}
//Featured Story
function featuredStory() {
$featuredPosts = new WP_Query();
$featuredPosts->query('cat=9&showposts=5');
while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
echo '<li><a href="' .get_permalink(). '" rel="bookmark">' . postimage(thumbnail) . the_title('', '', 0) . '</a></li>';
endwhile;
}
?>
And here is the resulting HTML:
<img src="http://domain/wp-content/uploads/2008/10/81023w1_gomez_s_b_gr_03-100x100.jpg" width="100" height="100" class="attachment-thumbnail" alt="" />
<li><a href="http://domain/?p=13" rel="bookmark">A gallery test</a></li>
As you can see the image function gets placed before any of the echoed HTML elements, so it looses it's hyperlink and styling.
Any help would be great!
Thanks everyone!