On the homepage of a wordpress install, I would like to display the latest post from each category with the category title, post attachment, post title, post excerpt, and post date.
The post attachment will always be a thumbnail version of the "featured image". The reason I wish to use the attachment and not the main image linked to the article, is we are using a plugin that alloows the editor to post a youtube link which overrides the featured image, so if I use "get_the_post_thumbnail" it pulls in the video instead of the image.
The code I am currently using from a mash up of solutions I have found is as follows:
<?php
query_posts('cat=3&showposts=1');
if(have_posts()) :
the_post();
$images = get_children(array(
'post_parent' => get_the_id(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'ID',
'order' => 'ASC',
'numberposts' => 1
));
foreach((array)$images as $key => $image){
echo wp_get_attachment_image($key);
echo "<a href='" . get_permalink() . "'>Link</a>";
}
the_excerpt();
endif;
wp_reset_query();
?>
My problems with the above are as follows:
1) I cannot figure out how to get the category name (I could just hard code this and repeat the above for each category, but that seems like cheating).
2) When I repeat this code for the next category the image or permalink do not show up. I assume this is because I am repeating references or something like that, but I am too amateur with Wordpress to know.
Any help will be much appreciated. The final result is to look like this : http://www.tagdesignuk.com/lovethat/
Regards,
Kevin
UPDATE:
I have simplified this now, but still am a little stuck. I have removed the video plugin as I will find an easier way to do this later on, so now my only problem is pulling in the correct sized thumbnail.
I am using the following code:
<?php
$catquery = new WP_Query( 'cat=3&posts_per_page=1' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php echo get_the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php the_date(); ?>
<?php endwhile; ?>
Any ideas on how to change the thumbnail size? The documentation (http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail) says to use as follows :
<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
but in the absense of a post ID it doesnt work... and I do not know how to format it correctly and cant find any reference to what I should be doing.
Many thanks,
Kevin