Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Inserting A Variable When Using is_page() Reply To: Inserting A Variable When Using is_page()

#190464
Anonymous
Inactive

If is_page() evaluates to false on all your town options then you don’t want anything to happen. I’m assuming that your variation options will never intentionally be set to false and am using the variable as an indicator for whether we are on a page for one of your towns.

If the variable were only created within the for loop, my if($variation) statement would produce an error on non-town pages (as $variation wouldn’t exist). Hence setting it to false first and trusting it’ll be changed to something that will evaluate to true if we are on a town page.

This would normally be handled by a router or a controller, by the way. This sort of coding is messy. A better method would be to find a way to pull the appropriate template in based on the variation – you only really need 3 lines of code (curly braces optional). I’ll leave that solution to your imagination.