Peter Knight Posted March 28, 2019 Share Posted March 28, 2019 Hi guys I have something working and I'm not sure it's the most efficient API usage. I want to display some content if the page is Vets or any sub page below Vets. My tree structure looks like this: Home Doctors Vets (ID 1116) - Vets sub page 01 - Vets sub page 02 - Vets sub page 03 - - Vets sub sub page 01 - - Vets sub sub page 02 - Vets sub page 04 Pilots Gardeners My working code is: <?php if ( $page->matches('id=1116') // Page is Vets Overview || // OR $page->parent->matches('id=1116') // Parent Page is Vets Overview ) { echo "My conditional content"; } ?> Thanks P Link to comment Share on other sites More sharing options...
Autofahrn Posted March 28, 2019 Share Posted March 28, 2019 I probably miss something and won't go through a selector for that purpose: <?php if ( ($page->id == 1116) // Page is Vets Overview || // OR ($page->parent->id == 1116) // Parent Page is Vets Overview ) { echo "My conditional content"; } ?> Any reason to use the same template for the overview and its children? Link to comment Share on other sites More sharing options...
Robin S Posted March 28, 2019 Share Posted March 28, 2019 Also see $page->rootParent if($page->rootParent->id === 1116) { echo "My conditional content"; } 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