Created
May 17, 2013 02:06
-
-
Save torounit/5596449 to your computer and use it in GitHub Desktop.
子ページを持つ親ページに、テーマ内に page-parent.phpがある場合、それを読み込む。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter("template_include", "get_parent_page_template"); | |
function get_parent_page_template( $template ) { | |
global $post; | |
if(is_page()) { | |
$children = wp_list_pages("child_of=".$post->ID."&echo=0"); | |
if( !$post->post_parent and !empty( $children )) { | |
$template = locate_template( array( "page-parent.php", "page.php" ) ); | |
} | |
} | |
return $template; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment