在page页面模板中加入下面这段代码:
global $post; // wodepress.com The following code needs to be used in the main loop. If you are using it outside the loop, you need to declare the global variable $post
if ( is_page() && $post->post_parent ) {
// This is a subpage
} else {
// This is not a subpage
}
制作wordpress模板的时候经常会用到,这是wordpress开发者必须要掌握的,如果你想开发wordpress模板,得把这个最基本的搞明白了。