WordPress.org

Ready to get started?Download WordPress

Forums

is_page equivalent for parents (6 posts)

  1. gblakeman
    Member
    Posted 6 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.

  2. MichaelH
    Member
    Posted 6 years ago #

    Couldn't you use the template tag, get_category_parents?

  3. gblakeman
    Member
    Posted 6 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
    Member
    Posted 6 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
    Member
    Posted 6 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 6 years ago #

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

    http://wordpress.org/support/topic/89781

Topic Closed

This topic has been closed to new replies.

About this Topic