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)

  • Are you setting the image through the 'Featured Image', or is it a custom field?
    – Pippin
    Jun 21, 2012 at 23:30
  • 'Featured Image' Jun 21, 2012 at 23:47

2 Answers 2


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()

  • 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" /> " Jun 22, 2012 at 0:07
  • Also made the changes per your note, " alt="View more info" /> " problem persists. Jun 22, 2012 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, 2012 at 0:26
  • IT is actually much easier to just use the_post_thumbnail('image-size')
    – Pippin
    Jun 22, 2012 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. Jun 22, 2012 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);?>
  • 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. Jun 21, 2012 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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