admin管理员组文章数量:1312902
I have a custom post type called communities. Then I have the appropriate single-community.php page. Works great!
So we want to use some of these "communities" as parent pages. Then underneath them we'd have multiple child pages.
Can I have the parent pages use single-community.php and the child pages use single.php or something similar?
I have a custom post type called communities. Then I have the appropriate single-community.php page. Works great!
So we want to use some of these "communities" as parent pages. Then underneath them we'd have multiple child pages.
Can I have the parent pages use single-community.php and the child pages use single.php or something similar?
Share Improve this question asked May 22, 2014 at 1:19 lz430lz430 1232 silver badges17 bronze badges 1- What have you tried so far? Any code you have written, modified or tried? Any research? – Brad Dalton Commented May 22, 2014 at 3:51
1 Answer
Reset to default 4You can filter template_include
and replace the single-community.php
with a single-child-community.php
.
Example
add_filter( 'template_include', function( $template ) {
if ( ! is_singular() )
return $template; // not single
if ( 'communities' !== get_post_type() )
return $template; // wrong post type
if ( 0 === get_post()->post_parent )
return $template; // not a child
return locate_template( 'single-child-community.php' );
});
本文标签: Can I make Wordpress use a custom template for a child page
版权声明:本文标题:Can I make Wordpress use a custom template for a child page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741907379a2404227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论