php - How can I add a field only if it is completed? -
i have site:
in page find link says "website", link complete administration panel.
the problem not companies have websites, , field must remain free.
if administration panel, field remains empty ... site use word "website" , link in new tab current page.
i put image understand better.

to see happens ... click on word website @ "bsl-student council".
i use wordpress , custom fields plugin.
i put , php code section
<div class="vright"> <p><?php echo substr(get_the_content(),0,300); ?></p> <?php $web = types_render_field("value_website", array("raw"=>"true","separator"=>";")); $strin = "<a target='_blank' href=\"".$web."\">website</a>"; echo $strin; ?> </div> you can me solve problem please?
thanks in advance!
edit: received suggestion , tried, below code still not work
<?php $web = types_render_field("value_website", array("raw"=>"true","separator"=>";")); if (isset($web)) { $strin = "<a target='_blank' href=\"".$web."\">website</a>"; echo $strin; } ?>
explaining if (isset($web) && $web != ""):
isset($web)checks if$webset (exists php variable) , notnull, blank ($web = "";).&&meansand.$web != ""check if$web(after checking if$webset) not blank (like$web = "";).
more info isset() here: http://php.net/manual/en/function.isset.php
your edited code be:
<?php $web = types_render_field("value_website", array("raw"=>"true","separator"=>";")); if (isset($web) && $web != "") { $strin = "<a target='_blank' href=\"".$web."\">website</a>"; echo $strin; } ?> your first code should be:
<div class="vright"> <p><?php echo substr(get_the_content(),0,300); ?></p> <?php $web = types_render_field("value_website", array("raw"=>"true","separator"=>";")); if(isset($web) && $web != "") { $strin = "<a target='_blank' href=\"".$web."\">website</a>"; } echo $strin; ?> </div>
Comments
Post a Comment