php if else help

Discussion in 'PHP' started by confused4l1f3, Mar 9, 2011.

  1. #1
    http://animefreakz.net/wp-content/uploads/2011/03/bgthum.png

    Im need to php coding will any one help me with this code.

    <?php if(get_post_meta($post->ID, "thumbnail", true)) : ?><a href="<?php the_permalink(); ?>" class="thumb"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" /></a><?php endif; ?>
    PHP:
    ok it gets the thumbnail value which is a img link.

    what if theres no value for thumbnail?

    how can i rewrite that code so if there is no value for thumbnail default would be
    http://animefreakz.net/wp-content/uploads/2011/03/bgthum.png
    PHP:
     
    confused4l1f3, Mar 9, 2011 IP
  2. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    How about adding an else with the default image.
     
    artus.systems, Mar 9, 2011 IP
  3. confused4l1f3

    confused4l1f3 Active Member

    Messages:
    231
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #3
    I tried adding the else but i think im doing it wrong or i put it in wrong place
     
    confused4l1f3, Mar 10, 2011 IP
  4. Client Management System

    Client Management System Peon

    Messages:
    19
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php if (get_post_meta($post->ID, "thumbnail", true)) : ?>
    
        <a href="<?php the_permalink(); ?>" class="thumb"><img src="<?php echo get_post_meta($post->ID, 'thumbnail', true); ?>" /></a>
    
    <?php else : ?>
    
        <a href="<?php the_permalink(); ?>" class="thumb"><img src="http://animefreakz.net/wp-content/uploads/2011/03/bgthum.png" /></a>
    
    <?php endif; ?>
    PHP:
    ** I'm by no means a Wordpress expert and had no chances to test this but it should work as expected.
     
    MaKaVeLLi and MobileWeb like this.
  5. confused4l1f3

    confused4l1f3 Active Member

    Messages:
    231
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #5
    Client Management System THANK YOU

    I see what I did wrong now

    I just had else not <?php else : ?>

    mixing up java with php..
     
    confused4l1f3, Mar 10, 2011 IP