I would like to display some html code if a variable is not empty, else I would like to display nothing.
I've tried this code but doesn't work:
<?php
$web = the_field('website');
if (isset($web)) {
?>
<span class="field-label">Website: </span><a href="http://<?php the_field('website'); ?>" target="_blank"><?php the_field('website'); ?></a>
<?php
} else {
echo "Niente";
}
?>
http://us.php.net/manual/en/function.empty.php
Seems like folks are complicating this a bit. Back to the original question, " ... if variable is not empty, echo some html code." "I would like to display some html code if a variable is not empty, else I would like to display nothing."
Easy way:
If your variable is not empty "Some HTML code here" will be displayed. If it is empty nothing will happen.