I'm running multiple queries on a front-page.php
file. They all seem to be working fine, except that I am having a hard time getting a thumbnail image.
The code in question, on my front-page, currently looks like this:
<?php
$thumb_args = array(
'posts_per_page' => 1,
'cat' => 87
);
$thumb_query = new WP_Query( $thumb_args );
while ($thumb_query->have_posts()) : $thumb_query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('cat-excerpt right') ?> itemprop="blogPost">
<h2 class="headline" itemprop="title">Posted Without Comment</h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<a href="<?php the_permalink(); ?>" itemprop="url">
<img src="<?php get_the_post_thumbnail('custom-medium'); ?>" itemprop="image">
</a>
</div><!-- End .post .cat-excerpt -->
<?php endwhile;
wp_reset_postdata();
?>
I have tried using both the_post_thumbnail()
on its own and get_the_post_thumbnail()
in an <img>
tag. When I use the_post_thumbnail()
(with or without passing an argument) it just returns an empty anchor tag, which links to the correct post. When I use get_the_post_thumbnail()
in an <img>
tag (with or without passing an argument, as seen above), I doesn't return the url for the image. The url for the actual post is always correct.
This is the code in my functions.php
file:
if (function_exists( 'add_theme_support' ) ) {
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-formats', array('audio','gallery', 'image', 'video'));
add_theme_support( 'post-thumbnails' );
if (function_exists( 'set_post_thumbnail_size' ) ) {
set_post_thumbnail_size( 620, 349, false );
}
}
if (function_exists( 'add_image_size' ) ) {
add_image_size( 'profile', 100, 100, false );
add_image_size( 'custom-small', 300, 169, false );
add_image_size( 'custom-medium', 400, 225, false );
add_image_size( 'custom-full', 520, 293, false );
}
The thumbnail image works fine in my single.php
file, which uses the default post thumbnail size that I defined above. So, if anything, I figure the issue is with the image sizes that I've added, and/or with my front-page.php
file.