Page 1 of 1

Adding ELSE to IF

Posted: Thu Oct 06, 2011 4:21 am
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

Re: Adding ELSE to IF

Posted: Thu Oct 06, 2011 4:24 am
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;
?>