Reputation: 103
How to set the_post_thumbnail
so that it doesn't use an array for its size, but instead can be set with a 100% width and auto height:
<?php $ht_featured_img = get_option('ht_featured_img');
if ($ht_featured_img == "true") { ?>
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { /* if post has a thumbnail */ ?>
<div class="post-image">
<?php the_post_thumbnail( array(1215,9999) ); ?>
</div><!--post-image-->
<?php } ?>
<?php } ?>
Upvotes: 10
Views: 23885
Reputation: 536
You could also just use
<img src="<?php echo get_the_post_thumbnail_url (); ?>" style="width:100%; height:auto;">
Upvotes: 2
Reputation: 71
<? if( has_post_thumbnail( $post_id ) ): ?>
<div class="post-image">
<img title="image title" alt="thumb image" class="wp-post-image"
src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">
</div>
<? endif; ?>
Upvotes: 6
Reputation: 668
<?php $ht_featured_img = get_option('ht_featured_img'); if ($ht_featured_img == "true") { ?>
<?php if ( ( function_exists('has_post_thumbnail') ) && ( has_post_thumbnail() ) ) {
$post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
?>
<div class="post-image">
<img title="image title" alt="thumb image" class="wp-post-image" src="<?php echo $post_thumbnail_url; ?>" style="width:100%; height:auto;">
</div>
<?php } ?>
<?php } ?>
Upvotes: 17