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 want use these code to load src of images that attachs in wordpress's post:

$recent = new WP_Query("showposts=30"); while($recent->have_posts()) : $recent->the_post();

        $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(80,80) );
        echo $thumb[0];

endwhile;

but my code don't work, and give me nothing.

please help me

share|improve this question
add comment

1 Answer

The following line is incorrect as showposts is deprecated.

$recent = new WP_Query("showposts=30");

Instead use,

$recent = new WP_Query('posts_per_page=30');

Following that,

Does the thumbnail size of 80x80 exist?

array(80,80)

If not try any of,

$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), small );
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), medium );
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), large );

Remember each of small, medium or large - refers to different filenames or src - so if you want to retrieve the full resolution image, original upload then use large.

If you must return the src URL as

http://domain.com/image_80x_80x.jpg //example

...meaning that you definitely want the 80x80 version and it does not exist then you will need to regenerate your thumbnails.

You can use: http://wordpress.org/extend/plugins/regenerate-thumbnails/

If you did not add the image size of 80x80 to your theme you can do so using the add_image_size function in your functions.php file,

add_image_size( 'my_custom_size', 80, 80 );

Now, when uploading new images, you will also get a 80x80 version. You can then refer to it as mentioned above by either,

wp_get_attachment_image_src( $id, array(80,80) ); //via array specifying pixel w & h

or

wp_get_attachment_image_src( $id, my_custom_size ); //via name used in add_image_size
share|improve this answer
    
thanks but new code don't work –  Ehsan Sep 20 '12 at 7:06
add comment

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.