schmoukiz
Member
Posted 10 months ago #
I'm looking for a method to get the address of the corresponding thumb for each article.
For displaying it in the loop I've managed just fine with this code:
<?php getpost_img($post->ID); ?>
It works great, the problem is it returns more than the actual image as in (/folder/filename.jpg). It produces something like:
<img style="float: left; margin-right: 9px; border: none;" src="http://www.domain.com/thumbnails/picture.jpg" width="130" height="130" alt="" title="" />
And I only need the src part within the quotation marks, to use it further in a meta tag.
All I could find so far didn't work, including $sThumbURL and
<?php wp_get_attachment_thumb_url( $post_id ) ?>
Or maybe I just didn't formulate correct the php request.
Try this:
<?php
$thumbid = get_post_thumbnail_id();
$thumbsrc = wp_get_attachment_image_src( $thumbid );
?>
(Must be used within the Loop, or else you'll have to pass $postid to get_post_thumbnail_id().)
schmoukiz
Member
Posted 10 months ago #
Thank you for your reply. It doesn't produce results in the meta area, outside the loop.
Since I don't know to pass variables, I've continued searching and found this in a comment somewhere:
<?php
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,’large’, true);
echo $image_url[0]; ?>
It works very well, though maybe your solution with the variable was simpler.
The code you posted is exactly the same thing that I posted. Both code examples use exactly the same two functions: get_post_thumbnail_id() and wp_get_attachment_image_src().
The only difference is that you're echoing the result.