gblakeman
Member
Posted 2 years ago #
I'm using the 'is_page' function in some templates to display different pieces of code on certain pages.
For example:
<?php
if (is_page('whoweare')) {
echo '<img src="/wp-content/themes/b2gnat/images/title_elsewhere_whoweare.png" width="178" height="17" alt="Elsewhere in Who We Are" />';
} else {
echo '';
}
?>
What I'm wondering is if there is a way to do the equivalent for child pages. For example, on any given child the template could query and figure out who the parent is, and if that matches display some code, if not display other code.
gblakeman
Member
Posted 2 years ago #
Hi Michael, I could be wrong, but I think the get_category_parents tag retrieves the parent category of child categories and not the name/slug of the parent of a child page
Yes, but since you have the category id of the parent, couldn't you use that to retreive the name?
Oops, forget that you mean parent Page not parent category.
Took me three readings to get that ;)
Okay how about this for finding the parent of page having ID of 47?
$parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID=47");
The code in this thread should be of some use for detecting the parent of a child Page:
http://wordpress.org/support/topic/89781