WordPress.org

Support

Support » How-To and Troubleshooting » if current page is in branch of sub-pages

if current page is in branch of sub-pages

  • Hello

    I am trying to test if the current page has a particular top-level page in its ancestry. I am using the get_post_ancestors function to build the array, then checking if it has the page id of 9 contained via an in_array function. Below is my code, but im not getting the output when the condition is met.

    if(in_array(9,get_post_ancestors($post->ID))) {
    				// Do Something
    }

    Is my syntax and logic ok?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Looks OK to me. Did you dump out $post->ID to see if it contains what you think it should? You could also assign the output of get_post_ancestors to a variable and dump that.

    whats the best way to dump the variables? Do I need to use FirePHP in order to retrieve php variables with Firefox and Firebug, or is there a better way to handle it?

    Thanks for the help

    I usually just put a print_r($variable); in for quick testing, but Firefox offers a lot more flexibility. I mostly develop in IE because that’s what the majority of viewers use and if I get it right for IE, Firefox generally is OK.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘if current page is in branch of sub-pages’ is closed to new replies.