
Untitled
By: a guest on
Apr 15th, 2012 | syntax:
None | size: 0.84 KB | hits: 6 | expires: Never
Add image as attachment link in Post topic
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'your-image-size' )
echo $image[0] ;is your link
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
<a href='<?php echo $image[0]; ?>'> my image link </a>
// Get URL of first image in a post
function postimage( $echo = true ) {
$image = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'order' => 'asc',
'orderby' => 'ID',
'post_mime_type' => 'image',
) );
$image_url = ( $image ) ? wp_get_attachment_url( current($image)->ID ) : "No Image";
if( $echo )
echo $image_url;
else
return $image_url;
}