• Hello!

    I’m trying to get my theme to display the content of a custom field if it exists, and if not to check to see if the page parent has a value in the same custom field – and if so display that.

    Top Level Page
    —> Child Page

    So, if the Child Page has the custom field value of “banner” show the banner, if not check to see if the Parent has that custom field of banner and show that instead.

    This isn’t working and I’m drawing a blank:


    <?php $parent_banner=get_post_meta($post_parent->ID, ‘banner’, true); ?>
    <?php $banner=get_post_meta($post->ID, ‘banner’, true); ?>
    <?php if ( $parent_banner ) : ?>

      <li style=”display: block; width: 100%;” class=”banner-image”><img src=”<?php echo $banner; ?>” height=”213″ width=”1032″ alt=”Banner Image” />

    <?php else : ?>

      <li style=”display: block; width: 100%;” class=”banner-image”><img src=”<?php echo $parent_banner; ?>” height=”213″ width=”1032″ alt=”Banner Image” />

    <?php endif; ?>

    I’m sure I’m missing something in my conditional tags, but no idea what!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ParticularlyEvil

    (@particularlyevil)

    I think I found my answer:

    <?php
    $parent_banner = get_post_meta( $post->post_parent, ‘banner’, true );
    $banner = get_post_custom_values(“banner”);
    if (empty ($banner)) {
    echo ‘

      <li style=”display: block; width: 100%;” class=”banner-image”><img src=”‘ . $parent_banner . ‘” height=”213″ width=”1032″ alt=”Banner Image” />

    ‘;
    } else {
    echo ‘

      <li style=”display: block; width: 100%;” class=”banner-image”><img src=”‘ . $banner[0] . ‘” height=”213″ width=”1032″ alt=”Banner Image” />

    ‘;
    }
    ?>

    Thread Starter ParticularlyEvil

    (@particularlyevil)

    This works, but doesn’t go down to grandchildren. Any suggested ways to improve this answer out there?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Page Parent's Custom Field if the Page Doesn't Have One’ is closed to new replies.