开发者

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

<?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>";
?>


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())


You need to have a matched pair of brackets around the whole if statement.

So either add an extra bracket at the start and end, or remove some of the unneeded ones like this:

<?php
if (!is_front_page() && !is_single() && !is_page())
   echo "<a href='http://chusmix.com/'>Cambiar Imagen</a>";
?>


It should look like this:

if (!is_front_page() && !is_single() && !is_page())
   echo "<a href='http://chusmix.com/'>Cambiar Imagen</a>";

You do not need a pair of parenthesis around each expression, but you need to wrap your condition.


I think you need an enclosing set of parenthesis around all three conditions:

if ((!is_front_page()) && (!is_single()) && (!is_page()))


<?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>";
}
?>

there are brackets missing to group the conditions conjunctive...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜