• Resolved VanNotenAlec

    (@vannotenalec)


    Hi, I got everyting working with the if else etc.

    Except when I try to check if the width of the ORIGINALLY uploaded ftrd img >= 1024px..

    This is what I got…

    Featured image = used as background.

    <!-- 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 -->
Viewing 2 replies - 1 through 2 (of 2 total)
  • How about this:

    <!-- SET BACKGROUND -->
    <?php
    		// Get the image ID as a string.
        $thumb_id = get_post_meta($post->ID,'_thumbnail_id', true);
        // Get an array containing the image url, width, and height.
        $thumb = wp_get_attachment_image_src($thumb_id, false);
        // Get the width of the image.
    		$width = $thumb[1];
    		// Get the height of the image.
    		$height = $thumb[2];
     	 if ( has_post_thumbnail() && !is_home() && !is_archive() && !in_category('discography') && $width >= 1024 ) {
        		$src = $thumb[0];
        	} else {
        		$src = get_bloginfo( 'stylesheet_directory' ) . '/img/bg/rotate.php';
        		// Use the PHP getimagesize function to get the dimensions of this image.
        		$image_info = getimagesize($src);
        		$width = $image_info[0];
        		$height = $image_info[1];
        	}
     ?>
    <div id="maximage">
        <img class="siteBackground" src="<?php echo $src; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="Site Background Image" />
    </div> <!-- #maximage -->

    I changed a bit of your code to make it more readable, and added the height and width for both images as attributes to the img tag so the end-users’ browser won’t have to calculate the size before rendering the page. That speeds things up. I also added the Alt attribute, since you’re supposed to always have that to validate HTML5.

    Thread Starter VanNotenAlec

    (@vannotenalec)

    You sir, are a hero!

    those last bits of coding where too much 😉

    it works like a charm!

    will post link to website as soon as it’s online 😉

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show featureed image when width >= 1024px’ is closed to new replies.