In my header I use this code:
if(is_page("stores")) {
// Do something
}
I run some code if on the page stores
but what I want to do is run that code if the page is stores
or any page that is a sub page of stores. Not only that, but is recursive so if we are on a sub sub sub page of stores
the code still runs.
When using pretty permalinks, I simply check against the request;
No extra DB queries, little computation, and works right down the tree!
Testing for sub-Pages section of Conditional Tags article in Codex has fitting code example that uses
get_post_ancestors()
to retrieve parent tree and loops through it with check.Handy little function
Usage:
check if current is a child of a page with the ID of 22