I need to display a custom-field value of page when I'm in a subpage too.
If you look at my code you can see a div id="desc".
<?php $header_image = get_header_image();
if ( ! empty( $header_image ) && !is_page('Home') ) { ?>
<div id="banner" class="clearfix">
<div class="banner-img">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
</div>
<div id="desc">
<div class="page-title"><?php wp_title(''); ?></div>
<?php the_meta(); ?>
<?php $btext = get_post_meta($post->post_parent, 'banner-text', true);
echo $btext;?>
</div>
<?php } // if ( ! empty( $header_image ) ) ?>
After display the page-title I need to check if I'm in page, I think something like:
if is a page then <?php the_meta(); ?>
else if is a subpage <?php $btext = get_post_meta($post->post_parent, 'banner-text', true); echo $btext;?> to display the parent custom-filed value.
What I need is to have in output the same structure in both cases so I can manipulate it via css only with a definition.
In the first case infact I'll have:
<div id="desc">
<div class="page-title"> Title</div>
<ul class="post-meta">
<li>
<span class="post-meta-key">banner-text:</span>
Lorem ipsum.... </li>
</ul>
</div>
but in the second:
<div id="desc">
<div class="page-title"> Title</div>
<ul class="post-meta"> </ul>
</div>
Lorem ipsum...
Arnav Joy answers:
try this
<?php $header_image = get_header_image();
if ( ! empty( $header_image ) && !is_page('Home') ) { ?>
<div id="banner" class="clearfix">
<div class="banner-img">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
</div>
<div id="desc">
<div class="page-title"><?php wp_title(''); ?></div>
<?php
if($post->post_parent == 0 )
the_meta();
else{
$btext = get_post_meta($post->post_parent, 'banner-text', true);
echo $btext;
}
?>
</div>
<?php } // if ( ! empty( $header_image ) ) ?>
Arnav Joy comments:
try using this code
<?php $header_image = get_header_image();
if ( ! empty( $header_image ) && !is_page('Home') ) { ?>
<div id="banner" class="clearfix">
<div class="banner-img">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
</div>
<div id="desc">
<div class="page-title"><?php wp_title(''); ?></div>
<?php
if($post->post_parent == 0 )
the_meta();
else{
$btext = get_post_meta($post->post_parent, 'banner-text', true);
echo '<ul class="post-meta">
<li><span class="post-meta-key">banner-text:</span>'.$btext.'</li>
</ul>';
}
?>
</div>
<?php } // if ( ! empty( $header_image ) ) ?>
natspace comments:
Thank you!
John Cotton answers:
Do you mean like this?
<?php $header_image = get_header_image();
if ( ! empty( $header_image ) && !is_page('Home') ) { ?>
<div id="banner" class="clearfix">
<div class="banner-img">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
</div>
<div id="desc">
<div class="page-title"><?php wp_title(''); ?></div>
<?php if($post->post_parent ) {
$btext = get_post_meta($post->post_parent, 'banner-text', true);
?>
<ul class="post-meta">
<li><span class='post-meta-key'>banner-text:</span><?php echo $btext; ?></li>
</ul>
<?php } else {
the_meta();
} ?>
</div>
<?php } // if ( ! empty( $header_image ) ) ?>
natspace comments:
Thank you!!
Luis Abarca answers:
Add this to your subpage
<?php
if ($post->post_parent) {
$parent = get_post($post->post_parent);
}
?>
<div id="desc">
<div class="page-title"> Title</div>
<ul class="post-meta">
<?php $btext = get_post_meta($parent->ID, 'banner-text', true); echo $btext; ?>
</ul>
</div>
Lorem ipsum...
Martin Pham answers:
please try this
<?php $header_image = get_header_image();
if ( ! empty( $header_image ) && !is_page('Home') ) { ?>
<div id="banner" class="clearfix">
<div class="banner-img">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
</div>
<div id="desc">
<div class="page-title"><?php wp_title(''); ?></div>
<?php if ( is_page() && $post->post_parent ) {
the_meta();
else {
echo get_post_meta($post->post_parent, 'banner-text', true)
} ?>
</div>
<?php } // if ( ! empty( $header_image ) ) ?>