Reputation: 10270
I am working on a custom Wordpress Site and I need to be able to output the image being assigned to the post as the "Featured Image" So, here is my PHP code
$theimage=wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID(), array( 160,260 ), false, '' ), 'product-image2');
$product_shortcode .= '<li>';
$product_shortcode .= '<a href="' . get_permalink() . '"><h4>'. get_the_title().'</h4>';
$product_shortcode .= '<img src="'.$theimage[0].'" alt="" /> ';
$product_shortcode .= '</a>';
$product_shortcode .= '</li>';
And now here is my problem
The image is being displayed in (160 x 140) As you can see. I need the image to be displayed wholly. When I inspected it the image src in output was ../~image-path/feed160x140.png. Which is the thumbnail size generated by wordpress. If it displayed the normal ../~image-path/feed.png I would be fine.
In my code, and according to the Wordpress Reference Website the array(160X260) should display it in those dimensions. Not happening for me.
I need help from the WP Gurus.
Upvotes: 0
Views: 274
Reputation: 5824
Try this, I hope this is working for you.
$theimage=wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()),'full');
$product_shortcode .= '<li>';
$product_shortcode .= '<a href="' . get_permalink() . '"><h4>'. get_the_title().'</h4>';
$product_shortcode .= '<img class="img-responsive" src="'.$theimage[0].'" alt="" /> ';
$product_shortcode .= '</a>';
$product_shortcode .= '</li>';
Used img-responsive
this class directly if you used bootstrap 3 other wise write css like.
.img-responsive{
height: 180px;
width: 100%;
display: block;
}
Upvotes: 2
Reputation: 9951
I deleted my first answer. I missed something very obvious.
You are using get_post_thumbnail_id()
which only take the post ID as a parameter, yet you are passing parameters for get_the_post_thumbnail()
. You are also passing a parameter that does not exist to to get_the_post_thumbnail
.
Instead of using
get_post_thumbnail_id(get_the_ID(), array( 160,260 ), false, '' )
You should use
get_the_post_thumbnail($post_id, array(160,260) );
Upvotes: 2