php - How can I add a field only if it is completed? -


i have site:

link

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.

enter image description here

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 $web set (exists php variable) , not null, blank ($web = "";).
  • && means and.
  • $web != "" check if $web (after checking if $web set) 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

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -