Skip to content

Instantly share code, notes, and snippets.

@torounit
Created May 17, 2013 02:06
Show Gist options
  • Save torounit/5596449 to your computer and use it in GitHub Desktop.
Save torounit/5596449 to your computer and use it in GitHub Desktop.
子ページを持つ親ページに、テーマ内に page-parent.phpがある場合、それを読み込む。
<?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