Skip to content

Instantly share code, notes, and snippets.

@mypacecreator
Last active Aug 29, 2015
Embed
What would you like to do?
page.phpで、子ページの場合も親ページの画像を使う
<?php
global $post;
if ( is_page() && $post->post_parent ): //子ページの場合
?>
<h1><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo get_page_uri($post->post_parent); ?>.jpg" alt="<?php echo esc_attr( get_the_title($post->post_parent) ); ?>" /></h1>
<?php else: //親ページの場合 ?>
<h1><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo get_page_uri($post->ID); ?>.jpg" alt="<?php the_title_attribute(); ?>" /></h1>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment