Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this function:

function get_image_link( &$post ) {
         $image_link_meta = get_post_meta( $post->ID, 'as_link_to_image', true ); 

         $image_link_from_post = '';

         if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $post->ID ) ) {
            $attachment_image_link = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), full );
         }

         if ( $attachment_image_link[0] )
            $image_link_from_post = $attachment_image_link[0];

         if( !empty( $image_link_meta ) ) 
            $final_image_link = $image_link_meta;

         elseif( !empty( $image_link_from_post ) )
            $final_image_link = $image_link_from_post; 

         else
            $final_image_link = WP_PLUGIN_URL . '/link/to/no-image.png';

         return $final_image_link;
    }
}

Any idea why $image_link_from_post isn't getting a value?

share|improve this question
1  
Cannot reproduce. Aside from missing quotes around full and extra bracket at the end this seems to be working. –  Rarst Feb 1 '11 at 6:41

2 Answers 2

up vote 1 down vote accepted

This should be able to return the url of the large image.

$largeImg = wp_get_attachment_link( $attachment_id, 'large', false );

There's also this incase that doesn't work.

wp_get_attachment_image_src( $attachment_id, 'large' );
share|improve this answer

This line right here:

if ( !$attachment_image_link[0] )
            $image_link_from_post = $attachment_image_link[0];

You're only assigning the $image_link_from_post variable to the post thumbnail if the post thumbnail does not exist. Take out the NOT operator in the conditional and it should work more the way you intend.

Update: oops, weird, I just copied that line out of your code, but now its not there. Did you already solve the problem?

share|improve this answer
    
corrected it.. it was a typo :-) –  Joann Feb 1 '11 at 0:01
    
Does the function work now for you? –  goldenapples Feb 1 '11 at 0:01
    
No, unfortunately.. –  Joann Feb 1 '11 at 0:05
    
In that case I'm not sure. You should quote 'full' in the call to get_post_thumbnail_id. Also, check for current_theme_supports( 'post-thumbnails' ) rather than function_exists( 'has_post_thumbnail' ), that's all I can offer. –  goldenapples Feb 1 '11 at 0:17
    
I added support to my theme already particularly in functions.php. Thanks for the time! –  Joann Feb 1 '11 at 0:22

Your Answer

 
discard

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.