WordPress.org

Support

Support » Themes and Templates » Only show featured image if width original file > 1023px

Only show featured image if width original file > 1023px

  • VanNotenAlec
    Member

    @vannotenalec

    Hi,

    I’m making a theme that uses the featured image as a background.

    so, if it’s more than or equals 1024px wide, display it, else go to the rotate.php.

    It all works, except for the ‘width check’.

    <!– SET BACKGROUND –>

    <?php
        $thumb = get_post_meta($post->ID,'_thumbnail_id',false);
        $thumb = wp_get_attachment_image_src($thumb[0], false);
    	$width = wp_get_attachment_image_src($thumb[1], false);
        $thumb = $thumb[0];?>
    <div id="maximage">
        <img class="siteBackground" src="<?php if ( has_post_thumbnail() && is_home() != 'true' && is_archive() != 'true' && in_category('discography') != 'true' && $width[1] > '1023' ) { echo $thumb; } else { echo get_bloginfo( 'stylesheet_directory' ) . '/img/bg/rotate.php';}  ?>" alt="" />
    </div> <!-- #maximage -->

  • The topic ‘Only show featured image if width original file > 1023px’ is closed to new replies.