Adding ELSE to IF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nick11380
Forum Newbie
Posts: 10
Joined: Sat Aug 20, 2011 10:20 am

Adding ELSE to IF

Post by Nick11380 »

Hi everyone,

I'm struggling to add an else function to this (WordPress) code:

<?php if ( get_post_meta($post->ID, 'cat-ipad', true) ) : ?>
<img style="float:left;margin-left:5px;margin-top:14px;cursor:help;" title="iPad Application" src="<?php echo get_post_meta($post->ID, 'cat-ipad', true) ?>">
<?php endif; ?>

It's pulling a custom field 'cat-ipad' however I want to add an image that replaces else 'cat-ipad'

Any help would be hugely appreciated,
Nick
Nick11380
Forum Newbie
Posts: 10
Joined: Sat Aug 20, 2011 10:20 am

Re: Adding ELSE to IF

Post by Nick11380 »

I've managed to fix this. Changed the structure to:

<?php
$catimg = get_post_meta($post->ID, 'cat-iphone', true);
if($catimg !=""){
$cimg = '<img style="float:left;margin-top:13px;cursor:help;" title="iPhone Application" src="'.$catimg.'">';
}else{
$cimg = '<img src="image" width="40" height="40">';
}
echo $cimg;
?>
Post Reply