I am searching for the right way of utilizing wordpress_get_attachment_image().
The next code:
<?php $args = array( 'type' => 'attachment', 'category_name' => 'portfolio' ); $attachments = get_posts($args); print_r($attachments); ?>
Creates the next result:
Array (  => stdClass Object ( [ID] => 54 [post_author] => 1 [post_date] => 2010-06-22 00:32:46 [post_date_gmt] => 2010-06-22 00:32:46 [post_content] => <a href="http://localhost/wordpress/wp-content/uploads/2010/06/Capture.jpg"><img class="alignnone size-medium wp-image-55" title="Capture" src="http://localhost/wordpress/wp-content/uploads/2010/06/Capture-300x114.jpg" alt="" width="300" height="114" /></a> [post_title] => Our Own Site [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => our-own-site [to_ping] => [pinged] => [post_modified] => 2010-06-22 00:40:22 [post_modified_gmt] => 2010-06-22 00:40:22 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wordpress/?p=54 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) )
The next, however, does not return anything.
<?php echo wp_get_attachment_image(54, array('300', '300')); ?>
What shall we be held doing wrong here?
Really, I do not think the recognized answer really solutions the question.
Your condition is the fact that you are passing within the publish id to wordpress_get_attachment_image(). As possible observed in the codex (http://codex.wordpress.org/Function_Reference/wordpress_get_attachment_image), you are designed to make use of the attachment id):
wp_get_attachment_image( $attachment_id, $size, $icon );
Quite simply, you need to make a move such as this:
$image_attr = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
wp_get_attachment_image only will get a picture which was submitted to wordpress, it does not output a picture within the content from the publish.
You need to output this content from the publish for the example image.