如何设置the_post_thumbnail
以使其不使用数组的大小,而是可以设置100%宽度和自动高度:
<?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 } ?>
答案 0 :(得分:16)
<?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 } ?>
答案 1 :(得分:5)
<? 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; ?>
答案 2 :(得分:1)
您也可以使用
<img src="<?php echo get_the_post_thumbnail_url (); ?>" style="width:100%; height:auto;">