PHP IF Statement with three && conditions not working in Wordpress

lisovaccaro picture lisovaccaro · Dec 9, 2010 · Viewed 22.1k times · Source
<?php
if (!is_front_page()) && (!is_single()) && (!is_page())
   echo "<a href='http://chusmix.com/'>Cambiar Imagen</a>";
?>

It's actually the elseif of a bigger if but I tried to do separately trying to increase my chances of making it work. The bigger statement is this one, all works except the elseif:

<?php
$res= get_search_query();
$image_path = 'Imagenes/grupos/' . substr(get_search_query(), 1) . '.jpg';

if (file_exists($image_path)) {    
    echo "<img src='http://chusmix.com/Imagenes/grupos/".substr(get_search_query(), 1). ".jpg'>";
    echo "<a style='padding-left:180px;' href='http://chusmix.com/'>Cambiar Imagen</a>";
    echo "<hr style='border: 0;'>";
}
elseif (!is_front_page()) && (!is_single()) && (!is_page())
   echo "<a href='http://chusmix.com/'>Cambiar Imagen</a>";
?>

Answer

BoltClock picture BoltClock · Dec 9, 2010

You're missing an outer set of parentheses:

elseif ((!is_front_page()) && (!is_single()) && (!is_page()))

You can leave out each individual pair that surrounds the function names though to make it look cleaner:

elseif (!is_front_page() && !is_single() && !is_page())