a way to test if pages are children of a parent?
-
Is there a way to test if a page is the child of a specific page so that you can then write specific code? For example, let’s say I have 3 main menu links that link to 3 “parent” Pages. Each of these have many, many sub (child) pages of their own.
In my header file (which houses this shared navigation code and markup), I want to say something like
<a href="/category/upcoming-events/" title="upcoming events" onmouseover="P7_autoLayers(1)" <?php if (is_page(3) || is_page(26)) {echo 'id="selected"';} else {} ?>>upcoming events</a>
But that is the easy one, as it only applies to 2 places in the site. The others have many children… so I want to try a more dynamic approach, rather than specifically stating the page ids… replacing this part
(is_page(3) || is_page(26))
with something that summarizes as “if child of page 4” {do this} else {dont do anything}
This would be for 3 other main menu links.
I hope I’ve explained this well. I know how to use child_of= in page lists, etc but have never found a clear answer of how to “test” or write conditional code that would return whether the current page was a child of a specific page id.
help SO greatly appreciated! Thanks for input in advance
- The topic ‘a way to test if pages are children of a parent?’ is closed to new replies.