Array to determine Subpage
-
I read in another closed thread the ability for someone to create a conditional based upon using the $post->post_parent feature. It looked like this:
<?php if (5 == $post->post_parent) { echo 'this post has a parent of 5'; } elseif (63 == $post->post_parent) { echo 'this post has a parent of 63'; } elseif (97 == $post->post_parent) { echo 'this post has a parent of 97'; } elseif (104 == $post->post_parent) { echo 'this post has a parent of 104'; } elseif (82 == $post->post_parent) { echo 'this post has a parent of 82'; } else { } ?>
This worked fine except that its a bit cumbersome. If its true for any of these ‘parent’ pages, then the subpage will have the same snippet of code. Where as now, I have to go in and place the same snippet for every condition. I tried this:
<?php if ( 5 || 63 || 97 || 104 || 82 == $post->post_parent) { echo 'this post has a parent'; } elseif ( is_page (array(5, 63, 97, 104, 82)) ) { echo 'no parent'; } else {} ?>
Doing that returned the same reply ‘this post has a parent’ regardless if it was the child post (page) or the parent.
Can someone help a brother out?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Array to determine Subpage’ is closed to new replies.