WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need help with if - else statement for featured image (2 posts)

  1. AardvarkGirl
    Member
    Posted 1 year ago #

    I've got a space in the header to use the featured image. What I'm trying to do is an if / else that IF there is a featured image, great load that puppy up WITH the html (the div). If there is no featured image, don't put anything (no div).

    Why? The client wants to be able to upload a photo there, and the photo is held in a div that has a white background, a 5px padding all the way around, and a drop shadow. This way they don't have to know how to edit graphics or send the photos to me.

    http://www.ratest6.com/about-us/

    If there is no featured image the div is showing up as a small white square (because it has the white background and 5px of padding).

    http://www.ratest6.com/links-and-resources/

    Right now I've got:

    <div class="banner">
             <?php
        if(has_post_thumbnail()){
            the_post_thumbnail('full');
        }
        else{
            echo '';
        }
    ?>
    </div><!-- end of banner -->

    Or, if there is a css solution I'm all ears too. :)

  2. AardvarkGirl
    Member
    Posted 1 year ago #

    Never mind, I worked it out:

    <?php
      if(has_post_thumbnail())
    	{echo'<div class="banner">';
            the_post_thumbnail('full');
         echo '</div>';}
    
      else{
         echo '';
        }
    	?>

Topic Closed

This topic has been closed to new replies.

About this Topic