I've got a system for post images where I have a specific category's post thumbnail shown in the header, with a cropped version appearing in the blog #preview, and the full size image appearing in the full post.
Images are not appearing in any of the 3 locations, and I'm not quite sure why.
functions.php-
<?php register_sidebar(); if (function_exists('add_theme_support')) { add_theme_support('post-thumbnails'); set_post_thumbnail_size(140,170); } if ( function_exists( 'add_image_size' ) ) { add_image_size( 'custom-image', 440, 265, true ); //(hard cropped) } function ravs_get_custom_image( $featured_img ){ global $post, $posts; $args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID, 'exclude' => $featured_img ); $attachments = get_posts( $args ); if ( $attachments ) { foreach ( $attachments as $attachment ) { $img = wp_get_attachment_image( $attachment->ID, 'custom-image' ); return $img; } }else{ echo 'Please attach images to your post'; } } ?> index.php
<?php echo get_header('cait');;?> <?php echo get_sidebar();;?> <div id="blog"> <div class="preview"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="post-image"> <?php echo ravs_get_custom_image( get_post_thumbnail_id () ); ?> </div><!-- end post-image --> <div class="post"> <h2><?php the_title() ;?></h2> <span class="post-preview"> <?php the_excerpt('read more...'); ?> <?php endwhile; else: ?> <p>Sorry, no posts to list</p> <?php endif; ?> </span><!-- end post-preivew --> <p class="post-meta"><span style="font-family: amatic;">>></span> Posted on <?php the_date('M-d-y'); ?> <span style="font-family: amatic;">>></span> <?php the_tags('tags: ', ', ', '<br />'); ?></p><!-- end post-meta --> </div><!-- end post --> </div><!-- end preview --> </div><!-- end blog --> <?php get_footer(); ?>
ravs_get_custom_image()with an image's post ID, and then you exclude it in theget_posts()call inravs_get_custom_image(). Why? (Also, you can double-check your post thumbnail ID with something likeecho( 'DEBUG: Thumbnail ID=' . get_post_thumbnail_id() . '<br />' );.)'exclude' => $featured_imgfrom functions.php? (Doing that makes no changes to the site.)