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.

As you know the result of the the_post_thumbnail() is an image tag. I need this image tag to store at a kind of collection or Array. I'm using the following code but it doesn't help me out. And I want to use it at another place and print out as an image tag.

<?php $tmp_query = new WP_Query('showposts=6');
$counter=0;
while ( $tmp_query->have_posts() ) : $tmp_query->the_post();

 $arr[$counter]=the_post_thumbnail();
 $counter++;
 <?php endwhile;wp_reset_query(); ?> 
share|improve this question
    
showposts is deprecated use posts_per_page instead –  JMau Aug 27 '13 at 9:18
    
JMau !!! thanks but my question is not about showposts!! –  user35212 Aug 27 '13 at 9:21
    
downvoted for lack of research: Codex codex.wordpress.org/Function_Reference/get_the_post_thumbnail –  Michael Aug 27 '13 at 9:23
    
Not a good reason for using deprecated code. –  JMau Aug 27 '13 at 9:23

3 Answers 3

Most WordPress functions that echo a result have sister function that return the result. To find them, go to the the Codex reference page for the function you are using. For this function, search Google with this phrase:

site:codex.wordpress.org the_post_thumbnail

Click on the link to the function then on the Related section and you will find other functions related to this one, including a link to the get_the_post_thumbnail() function.

The WordPress community has added most WordPress functions to the Function Reference and to the Template Tags sections of the Codex.

share|improve this answer

With a tiny bit of research, I'm pretty sure you could have created this yourself:

$imageid = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
$featimage = $imageid['0'];
$printable_url = '<img src="' . $featimage . '">';

echo $printable_url;
share|improve this answer

I too was rather confused by a similar attempt to use the_post_thumbnail() and it's alternate get_the_post_thumbnail(). Patrik's previous answer worked very well for me on that occasion, and I have since had good success with a combination of the two.

I had no luck with:

get_the_post_thumbnail('thumbnail');

but rather better success including $post->ID

get_the_post_thumbnail($page->ID, 'thumbnail');

The saddest part is that it is all in the WP codex... I just appear to have forgotten 'how' to read :)

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.