WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] is page child, grandchild, etc.

[Resolved] is page child, grandchild, etc.

  • 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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    @esmi

    Forum Moderator

    Try:

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

    I owe you a cold one 🙂

    Thanks!

    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?

    esmi

    @esmi

    Forum Moderator

    Try:

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

    Thank you 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] is page child, grandchild, etc.’ is closed to new replies.
Skip to toolbar