Get wordpress to show the src of a resized featured image

I want to display content from a blog on a corporate page. I am stuck with the thumbnail however–I have assigned a new image size (64x48px) and I have to get its src.

This is the code I’ve got, but it doesn’t work the way I want it to.

Read More
<?php
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
 ?>
<?php
    global $post;
    $args = array('posts_per_page' => 3, 'category' => 632);
    $externalSitePosts = get_posts($args);
    foreach($externalSitePosts as $post) : setup_postdata($post);
?>
<?php
    //This one gets me the src of the original file (full)
    $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post->ID, 'myResizedThumbnail'));
    echo $thumbnail;

    //This one displays the properly generated thumbanil image with the size as assigned in functions.php (64x48), I need the src though
    $thumbnail1 = the_post_thumbnail('myResizedThumbnail');
    echo $thumbnail1;
?>
<?php endforeach; ?>

Thank you! 🙂

Related posts

Leave a Reply

1 comment

  1. You’re looking for wp_get_attachment_image_src();

    <?php wp_get_attachment_image_src( $attachment_id, $size, $icon ); ?>

    It’s going to return

    [0] => url
    [1] => width
    [2] => height
    [3] => boolean: true if $url is a resized image, false if it is the original.
    

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

    So you’d do this:

    <?php
    
    $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID), 'myResizedThumbnail' );
    echo $thumbnail[0];
    
    ?>