Last active
May 5, 2016 20:19
-
-
Save mrfoxtalbot/d3e60622c76a8d709e35505a7fcb49c9 to your computer and use it in GitHub Desktop.
Check if page is grandchild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://wordpress.org/support/topic/conditional-statement-is-page-a-grandchild?replies=6 | |
http://wordpress.stackexchange.com/questions/182017/a-check-for-if-is-parent-page-if-has-children-if-has-grandchildren | |
<?php if( count(get_post_ancestors($post->ID)) == 2 ) echo 'this is grandchild of top page'; ?> | |
<?php if( count(get_post_ancestors($post->ID)) >= 2 ) echo 'this is grandchild of some page'; ?> | |
try and echo the post id before the code to see if it is the one of the page you are on: | |
maybe also add a is_page() conditional: | |
<?php | |
echo $post->ID; // should be the id of the current page | |
if( is_page() && count(get_post_ancestors($post->ID)) == 2 ) echo 'this is grandchild of top page'; ?> | |
where in your site are you using this code? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment