您可以随时使用page_template
过滤器告诉WordPress对某个父级的所有子页使用特定的页面模板。这就像创建一个特殊的页面模板一样简单,让我们调用它page-wpse-person.php
.
现在,只要在people
正在查看。为了举例说明,让我们假设people
是10
add_filter( \'page_template\', function ( $template ) use ( &$post )
{
// Check if we have page which is a child of people, ID 10
if ( 10 !== $post->post_parent )
return $template;
// This is a person page, child of people, try to locate our custom page
$locate_template = locate_template( \'page-wpse-person.php\' );
// Check if our template was found, if not, bail
if ( !$locate_template )
return $template;
return $locate_template;
});