Support » Fixing WordPress » is page child, grandchild, etc.

  • Resolved frescova

    (@frescova)


    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)
  • Try:

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

    Thread Starter frescova

    (@frescova)

    I owe you a cold one 🙂

    Thanks!

    Thread Starter frescova

    (@frescova)

    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?

    Try:

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

    Thread Starter frescova

    (@frescova)

    Thank you 🙂

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