the_post_thumbnail Breite auf 100 % setzen

Lesezeit: 2 Minuten

Brians Benutzeravatar
Brian

Wie einstellen the_post_thumbnail so dass es kein Array für seine Größe verwendet, sondern stattdessen mit einer Breite von 100% und einer automatischen Höhe eingestellt werden kann:

<?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="https://stackoverflow.com/questions/18906199/<?php echo $post_thumbnail_url; ?>" style="width:100%; height:auto;">
        </div>
    <?php } ?>
<?php } ?>

  • Fantastisch, das hat funktioniert! Vielen Dank!! Für title =”image title” habe ich schließlich verwendet: title=”” für den Fall, dass jemand anderes in Zukunft dasselbe braucht.

    – Brian

    20. September 2013 um 7:54 Uhr

<? if( has_post_thumbnail( $post_id ) ): ?>
    <div class="post-image">
        <img title="image title" alt="thumb image" class="wp-post-image" 
             src="https://stackoverflow.com/questions/18906199/<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">
    </div>
<? endif; ?>

  • Fügen Sie mehr als nur Code hinzu, erklären Sie, was Sie tun, wie es funktioniert und warum es eine Lösung ist.

    – Jojodmo

    3. Februar 2014 um 1:26 Uhr

Könnte man auch einfach verwenden

<img src="https://stackoverflow.com/questions/18906199/<?php echo get_the_post_thumbnail_url (); ?>" style="width:100%; height:auto;">

1394940cookie-checkthe_post_thumbnail Breite auf 100 % setzen

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy