0

I have two images attached to a page. One is being used as the featured image, and I want the other to automatically be displayed at the designated spot in the template (within the loop) at full size. The image I want is the first image attachment, so as I understand, I should be able to simply use:

<?php echo wp_get_attachment_image(1, 'full'); ?> 

But, this is returning nothing. What am I missing?

1
  • 1
    Is the 1 an example ID, or are you trying to use 1 as the attachment ID(i very much doubt there's an attachment with that ID). – t31os Mar 10 '11 at 14:26
5

Don't you need to use get_posts( 'post_type=attachment' ) to return the attachment IDs? So, something like:

$args = array( 
     'post_type' => 'attachment', 
     'numberposts' => -1, 
     'post_status' => null, 
     'post_parent' => $post->ID 
);    
$attachments = get_posts( $args );
$myimageid = $attachments[0]->ID;

wp_get_attachment_image( $myimageid, 'full' );

Otherwise, you're using $post->ID of 1, which isn't likely to work.

1
  • ID of 1 is guaranteed to fail, since the default installation post has that ID number no matter what. – John P Bloch Apr 8 '11 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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