two php code inside one php
Posted: Thu Nov 18, 2010 1:46 pm
Ok I am new to php and I have a wordpress blog and I am trying to pull a if-else statement together, that says if a certain field is not null then echo this code, if not show the field, here is how the code is functioning now:
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $curauth->yim; ?>" /> //basically displays an image file we indicate in the YIM field of a user
Now what we want it to do is "If" this field $curauth->yim; is not null "then" display <img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $curauth->yim; ?>" />
but if it is null we want to pull in some fields in that are already being collected by wordpress and they are also php based like:
$author_name
<?php bloginfo('name'); ?>
So i tried writing a if else statment:
Now Dreamweaver is showing a red highlight on the "else" line, not the echo line just on the else line, I then tried to just echo "hello" and else still is highlighted so I am thinking my issue is on the if echo line but do not know what it is. Any help would be most appreciated.
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $curauth->yim; ?>" /> //basically displays an image file we indicate in the YIM field of a user
Now what we want it to do is "If" this field $curauth->yim; is not null "then" display <img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $curauth->yim; ?>" />
but if it is null we want to pull in some fields in that are already being collected by wordpress and they are also php based like:
$author_name
<?php bloginfo('name'); ?>
So i tried writing a if else statment:
Code: Select all
<?php
if ($curauth->yim != null);
echo '<img src="' . bloginfo('stylesheet_directory'); '/images/' . $curauth->yim; '" />';
else
echo '<div id="author">' . bloginfo($author_name); '/div> <br> <div="title">' . bloginfo('name'); '</div>'
?>