0

i want to get image full path so that i can apply it in the src attribute of image element.

what i am getting right now is the image, generated from function: the_post_thumbnail(); which i can't apply to image element

what i did so far is:

            <?php
                $d=get_cat_ID( 'news' );
                $catquery = new WP_Query( 'cat='.$d.'&posts_per_page=1&order=DESC' );
                while($catquery->have_posts()) : $catquery->the_post();
                      the_post_thumbnail();
                endwhile;
            ?>

what i want is; path of image with its name as below:

http://example.com/folder1/wp-content/uploads/2013/12/image.jpeg

2 Answers 2

1

Use :

 $img = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );

 $img_src = $img[0];

refer this : http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

1

you can use wp_get_attachment_image_src. Below is small function for it.

function get_image_src( $post_id = '', $size_img = 'thumbnail' ) {
    if ( $post_id == '' ) {
        return false;
    } else {
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size_img );
        $image = $image[0];
        if( !$image ) {
            return false;
        }
    } 
    return $image; 
}

echo get_image_src(get_the_ID(), 'full'); //full size to get original image src

here get_the_ID() is post id in loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.