• I have a custom variable that denotes the URL of a picture I’m looking for, the problem is that it is displaying a blank box for the articles that don’t have a photo included. My question is, can someone help me create an if statement in PHP that can check the value of the variable, and only place the code for the image if the variable is NOT “” (blank).

    Here’s the code, should be everything that someone needs, I just don’t know Php really at all, so it’s tough for me:

    <img src="<?php $values = get_post_custom_values("MainFeaturedPost"); echo $values[0]; ?>" style="float: left; width: 517px"  alt="" />
                          <div id="photocreds">
                          Credit: <?php $values = get_post_custom_values("photocreds"); echo $values[0]; ?>
                          </div>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter abovegrnd

    (@abovegrnd)

    still looking for help on this one. thanks

    Hmm… no chance to test-drive but you might try this:

    $values=get_post_custom_values("MainFeaturedPost");
    
    if (isset($values))
    {
    <img src="<?php echo $values[0]; ?>" style="float: left; width: 517px"  alt="" />
                          <div id="photocreds">
                          Credit: <?php $values = get_post_custom_values("photocreds"); echo $values[0]; ?>
                          </div>
    }
    Thread Starter abovegrnd

    (@abovegrnd)

    I’ll try that thanks for the suggestion. Will it mess with other “$values” that may be defined on the same page?

    Thread Starter abovegrnd

    (@abovegrnd)

    okay so I’ve been working on this for a while again. Here is what I’ve come up with, but it doesn’t work…

    <?php $values = get_post_custom_values("MainFeaturedPost");
    if($values != ""){
    echo "<img src="<?php echo $values[0]; ?>" style="float: left; width: 517px"  alt="" />";
    }?>

    Getting:
    Parse error: syntax error, unexpected ‘?’ in /home1/abovegro/public_html/wp-content/themes/rgsimplistic/single.php on line 13

    Any help?

    Yes.

    <?php
    $values = get_post_custom_values("MainFeaturedPost");
    if($values != "")
    {
    echo "<img src='$values[0]' style='float: left; width: 517px' alt='' />"; }
    ?>

    Try this. You don’t need another <?php at that place. You already are IN a PHP statement.

    Thread Starter abovegrnd

    (@abovegrnd)

    Wearitwell, you are the man. Nailed it. Thanks a lot man. URL is https://abovegroundmagazine.com — Check it out, independent hip hop on a new level. Thanks so much.

    My dear! May I correct you… I’m the WOMAN ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Php if statement for displaying a picture’ is closed to new replies.