kaz Posted May 16 Share Posted May 16 I have an address in the global settings which is displayed on all pages in the sidebar. <?php if ($global->businesshours): ?> <?php include('businesshours.php'); ?> <?php endif; ?> The client asked me to hide the address on only one page, id 1127. I can have an element displayed on a single site via a query, if ($page->id == 1042 ), but can I also exclude a page in an include? Link to comment Share on other sites More sharing options...
bernhard Posted May 16 Share Posted May 16 Hey @kaz you can simply check for the opposite: <?php if ($global->businesshours && $page->id !== 1127): ?> <?php include('businesshours.php'); ?> <?php endif; ?> Which means if we have businesshours AND the page id is not 1127 then include ... Note that there is a difference between !== and != (and also === and ==) // Using == $var1 = "5"; $var2 = 5; if ($var1 == $var2) { echo "Equal"; // This will output "Equal" because values are the same after type juggling. } // Using === if ($var1 === $var2) { echo "Identical"; } else { echo "Not identical"; // This will output "Not identical" because types are different (string vs integer). } 1 Link to comment Share on other sites More sharing options...
kaz Posted May 16 Author Share Posted May 16 @bernhard Thanks that works great. And also thanks for the training. I am quietly learning from a book by Christian Wenz and Tobias Hauser, but some parts only become clear when I use :) 2 Link to comment Share on other sites More sharing options...
brandon sherrick Posted May 25 Share Posted May 25 (edited) Hello @kaz, Conditional Check within the Included File (businesshours.php). try to Modify businesshours.php to check if the current page ID should display the address. <?php if (!isset($global->businesshours) || $page->id != 1127) { // Display the business hours content echo $global->businesshours; } ?> Use an if statement before the include to check the page ID. kynect <?php if ($page->id != 1127) { include('businesshours.php'); } ?> If you have multiple places where you want to conditionally include or exclude the business hours based on the page ID, consider modifying businesshours.php for a reusable solution. If this is a one-time case for page 1127, using a conditional include might be simpler. Edited May 27 by brandon sherrick 1 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