Display Page Parent's Custom Field if the Page Doesn't Have One
-
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 PageSo, 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!
- The topic ‘Display Page Parent's Custom Field if the Page Doesn't Have One’ is closed to new replies.