bowenac Posted May 14, 2016 Share Posted May 14, 2016 In my footer, I'm checking if the page id equals a couple specific pages etc. I can only get this to work if I only check for one id... Not sure why this or statement is not working. if($page->id != 1021 || $page->id != 1105) if($page->id != 1021|1105) if( ($page->id != 1021) or ($page->id != 1105) ) I can't get any combination to work for some reason, but if I just check for one page id, what I'm trying to do works. But not when I check for multiple page id's... Link to comment Share on other sites More sharing options...
netcarver Posted May 14, 2016 Share Posted May 14, 2016 Your logic looks strange to me. I'd expect such a check to take a form more like one of the following; if ($page->id == 1021 || $page->id == 1105) { echo "I get run if the page id is 1021 or 1105"; } if ($page->id != 1021 && $page->id != 1105) { echo "I get run if page id is not 1021 and it is not 1105"; echo "ie (In English) I get run if page id is not 1021 or 1105"; } Does that help? 3 Link to comment Share on other sites More sharing options...
arjen Posted May 14, 2016 Share Posted May 14, 2016 Netcarver beat me An alternative: <?php if ($page->matches('id!=1021|1105')) { echo 'do stuff'; } 4 Link to comment Share on other sites More sharing options...
bowenac Posted May 14, 2016 Author Share Posted May 14, 2016 Thank you, a little early I guess. For some reason thought or would work... if page is this or that etc. Link to comment Share on other sites More sharing options...
Christophe Posted May 14, 2016 Share Posted May 14, 2016 There is also if (! Quick research via Google: For example, take a look at the current last answer here : http://stackoverflow.com/questions/6311040/php-if-not-equal-and-or-issue-why-doesnt-this-work (one example with || and one example with &&). 2 Link to comment Share on other sites More sharing options...
tpr Posted May 14, 2016 Share Posted May 14, 2016 IF logic, though seems simple, can be quite complex sometimes (or is it just me?) You could perhaps use !in_array(...) here, easier to read and grasp. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now