is_page equivalent for parents (6 posts)

  1. gblakeman
    Posted 8 years ago #

    I'm using the 'is_page' function in some templates to display different pieces of code on certain pages.

    For example:

    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.

  2. MichaelH
    Posted 8 years ago #

    Couldn't you use the template tag, get_category_parents?

  3. gblakeman
    Posted 8 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

  4. MichaelH
    Posted 8 years ago #

    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 ;)

  5. MichaelH
    Posted 8 years ago #

    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");

  6. Kafkaesqui

    Posted 8 years ago #

    The code in this thread should be of some use for detecting the parent of a child Page:


Topic Closed

This topic has been closed to new replies.

About this Topic