I haven’t tested this, but you might be able to use this (or something like it…):
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
<img src="<?php echo $url; ?>" longdesc="URL_2" alt="Text_2" />
http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id
http://codex.wordpress.org/Function_Reference/wp_get_attachment_url
Thanks trepmal!
I did try that code, it works but it gets the full size image url. For example,
http://www.website.com/wp-content/uploads/2010/09/AX0480GR2.jpg
the url for the thumbnail would be
http://www.website.com/wp-content/uploads/2010/09/AX0480GR2-300x298.jpg
I can’t find any documentation on how to get the exact URL for the generated thumbnail.. 🙁
Maybe this then?
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );
$url = $thumb['0']; ?>
http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
Still generates the full size URL
http://www.website.com/wp-content/uploads/2010/09/AX0480GR2.jpg
this is weird. Using the_post_thumbnail(), the URL path is the thumbnail’s but I’m not sure how that’s generated.
oops, I forgot to specificially mention that thumbnail_size
should be the name of the thumbnail size you’re using (I think the default is ‘post-thumbnail’?) – did you try swapping that out?
Here is where the the_post_thumbnail()
function is defined, you might be able to follow the trail: http://phpxref.com/xref/wordpress/wp-includes/post-thumbnail-template.php.source.html#l40
Trepmal you’re awesome! post-thumbnail works 🙂 I’ll add the code to my functions, it’s very useful 🙂
glad you got things working out
Worked like a treat, thanks 😉
Worked for me, thanks. Below is how I used it in it’s entirety – just in case anyone wants a quick C’nP.
<?php query_posts('category_name=Portfolio&order=ASC&orderby=date&posts_per_page=36'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
$url = $thumb['0'];
?>
<li><a style="background-image:url(<?=$url?>);" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"></a></li>
<?php endwhile; ?>
<?php endif; ?>
I’ve tried everything I’ve written here and nothing is working for me.
Can one of you help me please?
@Chozen Can you post what code you have so far? If it’s lengthy, please use something like http://pastebin.com/.