WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a portfolio page that will display a series of thumbnails and, when clicked on, will go to single.php. The code I'm using below seems to work in that when I click "see more" it goes to the proper page, however the thumbnails are not showing up. Any ideas as to why? Thanks.

Live site.


    <?php query_posts('cat=4'); ?>
    <?php if (have_posts()) : while ( have_posts() ) : the_post(); ?>

        <div class="portfolio-item">

            <?php //get article_image (custom field) ?>
            <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID )); ?>

            <a href="<?php the_permalink(); ?>"<img src="<?php echo esc_url( $image[0] ); ?>" alt="View more info" /></a>
            <p class="btn"><a href="<?php the_permalink(); ?>">See more</a></p>
        </div><!-- end portfolio-item -->
    <?php endwhile; ?>
    <?php endif;?>

    <?php wp_reset_query();?>

</div><!-- end work -->



// unregister all default WP Widgets
    function unregister_default_wp_widgets() {
    add_action('widgets_init', 'unregister_default_wp_widgets', 1);

// set thumbnail size    
    set_post_thumbnail_size( 130, 130, true ); // default Post Thumbnail dimensions (cropped)

share|improve this question
Are you setting the image through the 'Featured Image', or is it a custom field? – Pippin Jun 21 '12 at 23:30
'Featured Image' – user1255049 Jun 21 '12 at 23:47
up vote 0 down vote accepted

In your work.php code sample you are calling

get_post_meta( $post->ID, 'the_post_thumbnail', true)

This has nothing to do with WordPress post thumbnails and is looking for a custom field with the post meta key 'the_post_thumbnail'

For more info see:

To get the src url of the featured image attached to the post and use WordPress post thumbnails


<?php $image = get_post_meta($post->ID, 'the_post_thumbnail', true); ?>


<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));

when you echo the image:

<img src="<?php echo esc_url( $image[0] ); ?>" alt="View more info" />

The reason the array index [0] is added to $image is because wp_get_attachment_image_src returns an array(
[0] = img url attribute
[1] = img width
[2] = img height
To fix your php error add the missing } after your if_function_exists() { block.

Note: Unless your trying to make your theme backwards compatible to WordPress version 2.9 or earlier there is no need to call if_function_exists() on add_theme_support() or register_sidebar()

share|improve this answer
Thank you for your help. The error is fixed, and I've made your reccomended changes, however now in place of the thumbnail I see " alt="View more info" /> " – user1255049 Jun 22 '12 at 0:07
Also made the changes per your note, " alt="View more info" /> " problem persists. – user1255049 Jun 22 '12 at 0:13
Answer updated. I forgot you need to use wp_get_attachment_image_src() to return just the src attribute. – Chris_O Jun 22 '12 at 0:26
IT is actually much easier to just use the_post_thumbnail('image-size') – Pippin Jun 22 '12 at 1:10
Thanks for the update- it took care of the " alt="View more info" /> " issue, but still no thumbnails. I'll update work.php in my original post to reflect the changes. – user1255049 Jun 22 '12 at 1:12

Try this.

Go to functions.php and add this:

add_theme_support( 'post-thumbnails' );

This will enable theme support for post thumbnails, this way you can use featured image. Then, add this to functions.php:

add_image_size( 'portfoliothumbnail', xxx, yyy, true );

xxx is width you need for thumbnails, yyy is height.

After that, you can use featured images for post's and call them with:

<?php echo the_post_thumbnail($post->ID, "portfoliothumbnail", true);?>
share|improve this answer
I've already got that bit of info in my functions.php file. I'll post it all in my original post. ETA: I didn't read through what you wrote carefully enough. I'll make those changes now. Thanks. – user1255049 Jun 21 '12 at 23:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.