programing

_post_thumbnail 폭을 100%로 설정

lastmoon 2023. 4. 2. 11:48
반응형

_post_thumbnail 폭을 100%로 설정

설정 방법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 } ?>
<?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 } ?>
<? 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; ?>

또 다른 방법은

<img src="<?php echo get_the_post_thumbnail_url (); ?>" style="width:100%; height:auto;">

언급URL : https://stackoverflow.com/questions/18906199/setting-the-post-thumbnail-width-to-100

반응형