Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get url ONLY of featured image in wordpress

I'm using timthumb.php and need to be able to get the url of the featured image of a post, when I use functions like the_post_thumbnail it does more than just the url.

Here is the code so, the capital letters is where I need to insert the exact url, any help would be great, thanks.

<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> 
    <img src="<?php bloginfo('template_url'); ?>/wp-content/themes/limerickfc/timthumb.php?src=<?php URL OF FEATURED IMAGE ?>&h=760&width=474" alt="" title="<?php the_title(); ?>" />
</a>
like image 667
Adrian Avatar asked Nov 28 '22 16:11

Adrian


1 Answers

If your "thumbnail" images are large enough to do what you need:

<?php wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>

Otherwise you'll need to go for something like:

<?php $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(300, 300), false, ''); echo $src[0]; ?>

EDIT: The array(300, 300) bit is the image size you'd like to fetch. WP will substitute any image it has that is at least as large as what you asked for. You can also use 'thumbnail', 'medium', 'large' or 'full' to select one of the pre-configured sizes, as well as any name defined by add_image_size() in your template or plugins.

like image 89
smitelli Avatar answered Dec 06 '22 02:12

smitelli