I'm hoping that I can explain what I'm going for here. On my current project's main page, I'm displaying each post's Featured Image Thumb, along with an excerpt of the post's content. In each of the actual post pages, there is a default WP gallery with 2 to 4 images inside.
What I want to do, is make it so that my client doesn't always have to use a Featured Image in each post, so that the thumbnail always shows up on the home page. In other words, right now, he has to pick an image to be Featured in order for there to be that representative thumbnail for each post in the loop on the home page.
Can I make it so that even if he doesn't pick a featured image for a post, there still is a thumbnail to represent the post? Can I make it automatically just pick the first image in the post's gallery, if no featured image is chosen?
Just in case, here is some of what I'm using, code wise:
<div id="image-wrap">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div><!--end image-wrap-->
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title('<h2 class="entry-title"><a href="' .
get_permalink() . '" title="' . the_title_attribute('echo=0') . '"
rel="bookmark">', '</a></h2>'); ?>
<div class="entry-content">
<?php the_content(__('Continue reading', 'example')); ?>
<?php wp_link_pages('before=<p class="pages">' . __('Pages:','example') .
'&after=</p>'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<p class="no-posts"><?php _e('Sorry, no posts matched your criteria',
'example'); ?></p>
<?php endif; ?>
<?php wp_reset_query(); ?>
Then this is in my FUNCTIONS File:
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 100, true );
// Automatically makes featured image thumbs a clickable link
add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
function my_post_image_html( $html, $post_id, $post_image_id ) {
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr(
get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
return $html;
}
// This theme displays full size featured image on the Post's page
function InsertFeaturedImage($content) {
global $post;
$original_content = $content;
if ( current_theme_supports( 'post-thumbnails' ) ) {
if ((is_page()) || (is_single())) {
$content = the_post_thumbnail('page-single');
$content .= $original_content;
}
}
return $content;
}
add_filter( 'the_content', 'InsertFeaturedImage' );
http://dependablecarcompany.com is the address if you care to see what I'm talking about. You'll see what I mean when looking at the post titled: "1991 GMC Sierra". I did not use a featured image for the post, so there is no thumbnail shown. Thanks in advance!