Reputation: 44293
hey guys, i'm confused with this:
forceAnim: <?php echo (is_singular() || $iphone) ? 0 : 1; ?>
i have this forceAnim parameter in one function that could be either 0 or 1. is_singular means that a specific type of page is shown $iphone means it's viewed on the iphone.
i want forceAnmi ALWAYS to be 0 if it's viewed on the iphone and additionally i want forceAnim to be 0 if is_singular returns true.
what's the trick? currently if a singular page is viewed on the iphone forceAnim is 1.
regards matt
edit:
echo $iphone; //returns 1 only if on iphone
echo is_singular(); //returns 1 only if i'm on a singular page
both vars return 1 but just if they are true. so if i'm on the iphone $iphone returns 1, but if i'm not on the iphone $iphone doesn't return anythin (not 0) the same applies to is_singular()!
Upvotes: 0
Views: 143
Reputation: 7197
As others pointed out, make sure to check what is returned for is_singular()
and what is the value of $iphone
. It could be the values are not what you expect them to be.
On a side note, what about "simplifying" it with something like
forceAnim: <?php echo (int)(is_singular() || $iphone); ?>
Upvotes: 1
Reputation: 311
The Syntax is correct. You should check the return Value of "is_singular" and the Value in $iphone, since both of these seem to "evaluate" (!) to (boolean) false. Since PHP is a loosely typed language and you are using these Variables in a boolean context ( the || ) they are silently converted to bool - and both are converted to false, resulting in a (int) 1 as result of your expression - which is again silently converted to (string) 1, since "echo" is a string context.
Upvotes: 0
Reputation: 44376
Just replace both operands: ($iphone || is_sungular()) ? 0 : 1
.
OR
operator doesn't execute second operand if the first one is true. It means, if $iphone
is true then is_singular()
won't be even executed.
Upvotes: 0
Reputation: 360602
Try putting the entire ternary statement in brackets. PHP's operator precedence rules will cause the echo to echo out the results of the if() portion of the statement, rather than the results of the if():
forceAnim: <?php echo ((is_singular() || $iphone) ? 0 : 1); ?>
^-add this ^-and this
Upvotes: 0