1

I'm very new in PhP and trying to modify the code of may website.

I want to display a line only under certain condition but when I use if in the code, the site is showing blank

Thanks for your support

<?php 
if ( $property->post_type != 'land')
{
    <div class="property-drow">                                          
    <span>
<?php 
    if($site_language=='en_US') { 
        echo 'Age of Construction'; 
    } else { 
        echo 'Âge Construction'; 
    }
?>
    </span><p> {echo $construction;} ?></p>
    </div>
}?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Val
  • 11
  • 2
  • it would be easier to hide using css : see this question https://stackoverflow.com/questions/7020873/show-hide-div-if-if-statement-is-true (but there's an error in your php syntax.. paste it into https://phpcodechecker.com/ and it's report an error..) – Rachel Gallen Jun 24 '18 at 10:52
  • Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – mickmackusa Jul 02 '18 at 00:22

2 Answers2

1

Probably the best answer would be to tell you to add some error reporting to your code as you test

Add to the top of your file(s) while testing right after your opening PHP tag for example

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1);

// normal code

In this case you are not starting and stopping the PHP interpreter in the right places

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1);

if ( $property->post_type != 'land')
{
?>
    <div class="property-drow">                                          
        <span>
<?php 
    if($site_language=='en_US') { 
        echo 'Age of Construction'; 
    } else { 
        echo 'Âge Construction'; 
    }

?>
        </span>
        <p> <?php echo $construction;?></p>
    </div>
<?php
}
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

You have some html escaping issues.

To dry up your code you could consider using the ternary operator and short echo tag:

<?php if ($property->post_type != 'land'): ?>
    <div class="property-drow">
        <span><?=
        $site_language=='en_US' 
        ? 'Age of Construction' 
        : 'Âge Construction'
        ?></span><p><?= $construction ?></p>
    </div>
<?php endif; ?>
Progrock
  • 7,373
  • 1
  • 19
  • 25