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
Adding ELSE to IF
Moderator: General Moderators
Re: Adding ELSE to IF
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;
?>
<?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;
?>