WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is page child, grandchild, etc. (6 posts)

  1. frescova
    Member
    Posted 4 years ago #

    I want to display a specific header for specific pages.

    I can get this to work for immediate children of a page - i.e.

    <?php if ( is_page('americas') || $post->post_parent == '2348') { ?>
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/includes/css/styles-americas.css" />

    So - when I see a page that is a child of the page Americas (id: 2348) it displays the proper header.

    But, how do I set it up so that when I see a page that is a "grandchild" of Americas the header also displays properly?

    My hierarchy is something like this:

    parent page = Americas
    child page = Virginia
    grandchild page = Arlington

    right now the code above only works when I view "Virginia"; I also want it to work when I view "Arlington".

    Make sense? Thanks in advance for any input/guidance.

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Try:

    <?php if ( is_page('americas') || $post->post_parent == '2348' || in_array( '2348', $post->ancestors) ) { ?>

  3. frescova
    Member
    Posted 4 years ago #

    I owe you a cold one :-)

    Thanks!

  4. frescova
    Member
    Posted 4 years ago #

    Spoke too soon...

    It's working great if I'm viewing a child or grandchild page, but when I'm on any other page or post I get the following warning:

    `Warning: in_array() [function.in-array]: Wrong datatype for second argument in /html/wp-content/themes/theme1/header.php on line 52'

    Any ideas?

  5. esmi
    Forum Moderator
    Posted 4 years ago #

    Try:

    <?php if ( is_page('americas') || $post->post_parent == '2348' || ($post->ancestors && in_array( '2348', $post->ancestors) ) ) { ?>

  6. frescova
    Member
    Posted 4 years ago #

    Thank you :-)

Topic Closed

This topic has been closed to new replies.

About this Topic