我目前正在研究Wordpress主题,需要自动为子页面和孙子页面设置自定义模板,因此客户无需担心选择要选择的模板。
我已经有的代码是:
<?php
if( $post->post_parent !== 0 ) {
get_template_part('child');
} else {
get_template_part('parent');
}
?>
代码放在page.php中。这对于子页面非常有用,但我需要包含类似“如果孙子应用grandchild.php&#39;”的内容。
非常感谢任何帮助或建议。谢谢= D
答案 0 :(得分:0)
试试这个......
if( count(get_post_ancestors($post->ID)) >= 2 ) {
enter code here
}
利用http://codex.wordpress.org/Function_Reference/get_post_ancestors