WordPress.org

Forums

Only show featured image if width original file > 1023px (1 post)

  1. VanNotenAlec
    Member
    Posted 2 years ago #

    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 -->

Topic Closed

This topic has been closed to new replies.

About this Topic