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.

Is it possible to print two different url's from the same featured image/thumbnail?

So i have set up my image size..

add_image_size( 'full-size', 460, 9999 ); 
add_image_size('fixed-height', NULL, 75, false);

I need to pull the url of these two images sizes into the post like so..

<li><img src="full-size.jpg" ref="fixed-height.jpg" ></li>

Obviously i could not use the normal way..

<li><img src="<?php the_post_thumbnail('full-size'); ?>" ref="<?php the_post_thumbnail('fixed-height'); ?>" ></li>

Is it possible to do what i'm after, or no go?

Thanks for anyone that can help :)

share|improve this question

2 Answers 2

up vote 0 down vote accepted

no problem to have 2 or more post thumbnails of different sizes. but what is the "ref" attribute ? do you mean "rel" ?

anyhow - example from the :codex

 <?php 
 if ( has_post_thumbnail()) {
   $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
   echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
   the_post_thumbnail('thumbnail');
   echo '</a>';
 }
 ?>

mind that the_post_thumbnail() will give you the full HTML for the image , to get other attributes, you will need to use get_the_post_thumbnail() or get_post_thumbnail_id() with wp_get_attachment_image_src

    $fullsize = wp_get_attachment_image_src( get_post_thumbnail_id(), 'fullsize' );
    $fixed_height = wp_get_attachment_image_src( get_post_thumbnail_id(), 'fixed_height' ) ;
// returns array in which :
echo $fullsize[0] ;// url of fullsize 
echo $fixed_height[0] ;// url of fixed_height
share|improve this answer
    
Its for the image gallery pikachoose.com it requires ref. Thanks i've found a way using get_the_post_thumbnail –  Jezthomp Feb 27 '12 at 16:01

I would combine the_post_thumbnail() with get_intermediate_image_sizes(), e.g.:

<?php
// globalize $post object
global $post;

// Get the array of registered image sizes
$image_sizes = get_intermediate_image_sizes();

// Loop through the image sizes, and 
// use them to output the Featured Image
foreach ( $image_sizes as $image_size ) {
    echo '<li>';
    the_post_thumbnail( $post->ID, $image_size );
    echo '</li>';
}

?>

Note: I don't think get_intermediate_image_sizes() sorts the array of image sizes, so you may need to manipulate the return value, if you want to output the images ordered by size.

share|improve this answer

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.